How do I share user preferences or files using UserAppDataPath through an assembly?

Right now, when I release a new assembly of my .NET application, the UserAppDataPath points to the new folder that contains the assembly number.

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

I am using this path as a convenient place to store the extended user interface files. Every time I release, the user loses their previous UI settings.

Is it safe to disable version number 1.0.0.0 and use its root path? or is there a better way to keep the settings in a place where there is always write permission?

+2


source to share


2 answers


AppSettings support updates. Take a look here . Hopefully this indicates that you are in the right direction ...



+2


source


I am using the following code when retrieving user data stored in potentially old folders from previous build 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
    }

      

0


source







All Articles