Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top