Obtaining the Application Data Folder correctly

G

Guest

Our application needs to write some application specific data, but I have
not been able to find the recommended method to obtain the correct pathname.

I have found many references to the SHGetFolderPath function, but have not
been able to find any way to access this in VB.Net. Apologies in advance if I
have missed something obvious...

I have implemented this in the following function, using the Registry Key
HKEY_CURRENT_USER\Volatile Environment\APPDATA - is this a valid way to
obtain the Application Data Folder?

Protected Function GetApplicationDataFolder() As String
Dim AppDataRegKey As Microsoft.Win32.RegistryKey =
Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Volatile Environment")
If AppDataRegKey.GetValue("APPDATA") Is Nothing Then
MessageBox.Show("Error: Application Data Path not found",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Else
Return CType(AppDataRegKey.GetValue("APPDATA"), String)
End If
End Function


Thanks for any assistance,
Tim Failes
Advanced User Systems
 
A

Alexander Shirshov

Tim,

You could get a path to user's specific application data folder using:

Environment.GetFolderPath(SpecialFolder.ApplicationData)

and create a folder there for your application's data.



HTH,

Alexander Shirshov
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top