Obtaining the Application Data Folder correctly

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
Back
Top