38

I'm wondering what is the magic behind .settings files in .NET. Imagine you create an assembly called in this example SettingsHolder, you create your settings class which is public with a string inside in user mode , then you compile.

Now you reference your assembly in MyApp, you compile then you can change the value in your application of your setting with the settings class generated in SettingsHolder and persist them.

Now go in the output directory of MyApp and there is no trace of your setting (nothing in the application configuration file, nothing in the assembly, nothing !).

What is going on?! (I have tried to source step debug in .NET source, and reflector to see what is happening, .NET seems to use LocalFileSettingsProvider (but it seems weird to me because there is nothing in MyApp.exe.config in the output directory).

0

4 Answers 4

58

The setting files are stored in a different place for each user. To find them, click the start menu, click run, and paste:

%USERPROFILE%\Local Settings\Application Data\

and press enter. There will be a folder with your "Company Name" (whatever it is set to in your assembly) and then some more subfolders. The settings are stored in user.config.

Full path:

%USERPROFILE%\Local Settings\Application Data\<Company Name>\
<appdomainname>_<eid>_<hash>\<verison>\user.config.

In Windows Vista and newer, these are stored under:

%USERPROFILE%\AppData\Local\

More info:

3
1

On OS >= Vista I will claim the the user-setting file it's located here:

%LOCALAPPDATA%\ yourcompany \ app-name \ ..\user.config

0

In windows 11:(Assuming Windows is installed on drive C:)

C:\Users\YourUserName\AppData\Local\YourApplicationName\

There there is a another folder which contains a version folder and finally inside that user.config file. All settings are inside this file.

-4

The settings file is contained inside the compiled assembly.

Edit:

Just to clarify a bit. The code to get and set the settings from the file are compiled into the assembly. The values themselves are moved into Program.exe.config where Program is the name of your application. Reflector will let you see the code that gets and sets the value including the hard-coded key to the config file. The config file itself will show you the value and allow you to change it after the application has been built.

4
  • I don't see my settings file in the resources of my assembly with the reflector. Jan 22, 2009 at 16:09
  • 1
    Slashene: It's not an embedded resource, a C# code file is generated and it's compiled as a class in the assembly. Jan 22, 2009 at 16:13
  • The class Settings is just a wrapper, moreover you can change the value of your setting, if the value was hard coded in this class, you could not change the value of the setting Jan 22, 2009 at 16:16
  • 4
    Your answer only applies to settings when set to the Application level. The question specifically stated that this was in user mode. Also, you cannot modify the Application level settings (in program.exe.config). They are read-only.
    – ine
    Jan 22, 2009 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.