Properties.Settings.Default.Save() almacena el archivo user.config en un directorio con un hash

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

esto con el _Url_[some_hash] is pretty ugly, how can I remove it?

preguntado el 04 de julio de 12 a las 09:07

You can't. That is how it works. -

Where I tried it the first time, it worked without _null_[some hash] -

If it is a user setting it will be saved there. Perhaps an application setting affects the app.config (not sure however). -

2 Respuestas

You can! Just follow este artículo 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.

contestado el 23 de mayo de 17 a las 13:05

Respondido 04 Jul 12, 09:07

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. - eduardo ned harvey

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.