tags:

views:

1655

answers:

2

Hi,

I'm wondering what is the magic behind .settings files in .NET. Imagine you create an assembly called in this exemple 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 wierd to me because there is nothing in MyApp.exe.config in the output directory).

Thanks for your responses. ;)

A: 

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.

Andrew Hare
I don't see my settings file in the resources of my assembly with the reflector.
Nicolas Dorier
Slashene: It's not an embedded resource, a C# code file is generated and it's compiled as a class in the assembly.
Mehrdad Afshari
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
Nicolas Dorier
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.
amdfan
+6  A: 

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.

More info:

amdfan
In Windows Vista and newer, these are stored under %USERPROFILE%\AppData\Local\
Robin Clowers