2

Right now when I release a new build of my .NET app, the UserAppDataPath path points to a new folder that includes the build number.

Documents and Settings\UserName\Application Data\Company\AssemblyName\1.0.0.0

I use this path as a convenient storage place for extended user UI setting files. Every time I release the user looses their previous UI settings.

Is it safe to trim off the \1.0.0.0 version number and use its root path? or is there a better way to store settings in a place that is always has write privileges?

Tim Santeford
  • 27,385
  • 16
  • 74
  • 101
  • How are you deploying the application? It's been awhile since I've used it, but I believe ClickOnce allows for migrating previous settings. – Agent_9191 Oct 12 '09 at 20:43
  • I know this is not the best way to release but my company just places the release binaries into a shared folder and a login script updates everyone's installation. – Tim Santeford Oct 12 '09 at 20:45
  • I'm not allowed to use ClickOnce at this point – Tim Santeford Oct 12 '09 at 20:46

2 Answers2

2

AppSettings do support upgrades. Have a look here. Hopefully this points you in the right direction...

Nader Shirazie
  • 10,736
  • 2
  • 37
  • 43
  • Will that work for files other than the app.config? I have been storing other files along with the app.config? – Tim Santeford Oct 12 '09 at 20:49
  • Depends on what you mean by 'other' files, and how they're implemented. Are they custom settings, or using .NET's built in settings support classes? This should work for settings that implement the 'IApplicationSettingsProvider' interface. – Nader Shirazie Oct 12 '09 at 21:09
0

I am using the following code when retrieving custom data stored in potentially old folders from previous assembly versions:

    string suffix = "/MyUserSettings.dat";
    string folder = Application.UserAppDataPath;
    string filename = folder + suffix;

    if (!File.Exists(filename))
    {
        // Check whether an older folder from a previous version with appropriate user data exists
        DirectoryInfo[] directories = new DirectoryInfo(folder).Parent.GetDirectories("*", SearchOption.TopDirectoryOnly);
        for (int i = 0; i < directories.Length; i++)
        {
            if (File.Exists(directories[i].FullName + suffix))
            {
                filename = directories[i].FullName + suffix;
            }
        }
    }

    if (File.Exists(filename))
    {
        // load user settings from file
    }
    else
    {
        // use default settings
    }
Thomas853
  • 517
  • 1
  • 7
  • 12