I use the standard way of storing the settings of the Properties\Settings.settings application

Settings are placed in a file along the following path: %LOCALAPPDATA%\MyApp\MyApp.exe_Url_l2acnwn1eoostrlvwy2ik02hnoqwsfuq\1.0.0.0\user.config

Where does the name of the application MyApp come from and how can I get it in code?

I tried to change in the settings the Assembly name - only part of MyApp.exe_Url_l2acnwn1eoostrlvwy2ik02hnoqwsfuq has changed, but MyApp not changed.

I tried to edit the Title and Product in Assembly Information - to no avail, only the properties of the application change, the path to the settings does not change.

When changing the version of the application in Assembly Information only the part of the path responsible for the version changes (logically): 1.0.0.0

    1 answer 1

    The path to the configuration is as follows:

    %LOCALAPPDATA%\(Company name)\(EXE file name)_(AppDomain ID)\(Version)\user.config

    (Company name) is the name of the company, which is taken from the AssemblyCompany attribute in the assembly properties.

     var ass = System.Reflection.Assembly.GetExecutingAssembly(); var attr = ass.GetCustomAttributes( typeof(System.Reflection.AssemblyCompanyAttribute),true); if (attr.Length > 0) { string company = ((System.Reflection.AssemblyCompanyAttribute)attr[0]).Company; } 

    If this attribute is empty or consists of inappropriate characters, instead .NET tries to use the same string from FileVersionInfo . If it is also empty, the first (to the point) part of the namespace in which the Program class is located ( assembly.EntryPoint.ReflectedType.Namespace ) is used. The full algorithm for selecting this line can be viewed in the source .

    The final path to the configuration can be obtained programmatically as follows (add a link to System.Configuration):

     System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration( System.Configuration.ConfigurationUserLevel.PerUserRoamingAndLocal ); MessageBox.Show(config.FilePath); 
    • hmm, what if there is an empty string? (I have that way) - Andrew NOP
    • Added AssemblyCompany - now it is taken, but if it isn’t there, it’s not clear ... - Andrey NOP
    • @AndrewNOP There it is taken either from the file version data or the namespace. Updated. - MSDN.WhiteKnight
    • Cool! Thank you! You could still unravel this tangle in the references! Checked: changed the namespace with the App-file (I have a WPF project) - the location of the file with the settings has changed. - Andrey NOP