Saving Settings

by Andrew Jackson 3. June 2004 17:52

It's always a problem giving users settings they can change.. where exactly should you save these... first it was win.ini, then the registry and now it's the users application data folder.

This new place has the advantages that it's user specific and relatively secure and it's easy to see/edit/move to another machine.

.net has Application.UserAppDataPath which returns the current recommended path for application data for this application.  Unfortunately it also appends the current version number of the application, which although good for large applications where versions may change radically, for minor revisions it's annoying in that every new build would effectively loose users settings and they'd have to set it up again (or copy the file)

I've knocked up this simple function that simply removes the version info and returns a path that can then just have your settings file appended to get a consistent path.  Thought I'd share it here for the masses;

Public Function AppSettingsPath() As String
Dim AppPath As String
Dim LastSlash As Int16
AppPath = Application.UserAppDataPath
LastSlash = InStrRev(AppPath, "\")
Return AppPath.Substring(0, LastSlash)
End Function

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | VB.net

Comments

Comments are closed

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen