4

I try to save user settings. To save some data I used this code:

Properties.Settings settings = Properties.Settings.Default;
settings.Key1 = "value";
settings.Save();

but it saves the user.config file under the following path:

C:\Users\Me\AppData\Local\[CompanyName]\[ExeName]_Url_[some_hash]\[Version]\user.config

this with the _Url_[some_hash] is pretty ugly, how can I remove it?

David
  • 4,027
  • 10
  • 50
  • 102

2 Answers2

4

You can! Just follow this article that explain everything in full details, then you have to modify the property UserConfigPath as follows:

        private string UserConfigPath
    {
        get
        {
            System.Diagnostics.FileVersionInfo versionInfo;
            string strUserConfigPath, strUserConfigFolder;

            strUserConfigPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.Create);
            versionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location);
            strUserConfigPath = Path.Combine(strUserConfigPath, versionInfo.CompanyName, versionInfo.ProductName, versionInfo.ProductVersion, "user.config");
            strUserConfigFolder = Path.GetDirectoryName(strUserConfigPath);
            if(!Directory.Exists(strUserConfigFolder))
                Directory.CreateDirectory(strUserConfigFolder);
            return strUserConfigPath;
        }
    }

In this way you build the path from scratch. You should also modify the method CreateEmptyConfig in order to have a default action when the user.config file is not found.

Community
  • 1
  • 1
-3

see more info here http://msdn.microsoft.com/en-us/library/aa730869%28v=vs.80%29.aspx

JohnnBlade
  • 4,261
  • 1
  • 21
  • 22
  • 1
    I don't know if there used to be an answer on that msdn page, or if it's somehow there and I'm not seeing it. I don't see an answer on that msdn page, and I think this answer should be updated (including writing, or copy/pasting the relevant information) or rejected as an answer. – Edward Ned Harvey Feb 08 '16 at 22:03