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).

Robert
  • 1,286
  • 1
  • 17
  • 37
Nicolas Dorier
  • 7,383
  • 11
  • 58
  • 71

4 Answers4

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:

Bjarki Heiðar
  • 3,117
  • 6
  • 27
  • 40
ine
  • 14,014
  • 8
  • 55
  • 80
  • 17
    In Windows Vista and newer, these are stored under %USERPROFILE%\AppData\Local\ – Robin Clowers Apr 12 '10 at 17:40
  • The definitive way to find this path which works across different Windows versions is described here: https://stackoverflow.com/a/48881353/1688738. – Hugh W Jan 27 '23 at 15:23
  • If you are losing your user settings when a new build of your app causes the hash to change, see https://stackoverflow.com/a/1928041/1499294 – Daz Aug 23 '23 at 10:25
1

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

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

MrCalvin
  • 1,675
  • 1
  • 19
  • 27
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.

S Nash
  • 2,363
  • 3
  • 34
  • 64
-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.

Community
  • 1
  • 1
Andrew Hare
  • 344,730
  • 71
  • 640
  • 635
  • I don't see my settings file in the resources of my assembly with the reflector. – Nicolas Dorier Jan 22 '09 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. – Mehrdad Afshari Jan 22 '09 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 – Nicolas Dorier Jan 22 '09 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 '09 at 16:30