When using a Settings.settings file in .NET, where is the config actually stored?
It depends on whether the setting you have chosen is at "User" scope or "Application" scope.
User scope
User scope settings are stored in
C:\Documents and Settings\ username \Local Settings\Application Data\ ApplicationName
You can read/write them at runtime.
For Vista and Windows 7, folder is
C:\Users\ username \AppData\Local\ ApplicationName
or
C:\Users\ username \AppData\Roaming\ ApplicationName
Application scope
Application scope settings are saved in AppName.exe.config
and they are readonly at runtime.
Where are user-mode .NET settings stored?
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:
- http://www.codeproject.com/KB/vb/appsettings2005.aspx
- http://www.google.com/search?q=.net+user.config
Where are the settings saved in a .NET 5 WinForms app?
User settings are stored in user.config
file in the following path:
%userprofile%\appdata\local\<Application name>\<Application uri hash>\<Application version>
Application settings file are not created by default (unexpectedly), however if you create them manually beside the dll/exe file of your application, the configuration system respect to it. The file name should be <Application name>.dll.config
. Pay attention to the file extension which is .dll.config
.
You may want to take a look at the source code of the following classes:
- LocalFileSettingsProvider (The default setting provider)
- ClientSettingsStore
- ConfigurationManagerInternal
- ClientConfigurationPaths
At the time of writing this answer Application Settings for Windows Forms still doesn't have any entry for .NET 5 and redirects to 4.x documentations.
Where are the Properties.Settings.Default stored?
In order to work with newer versions of Windows' policy of only allowing read access by default to the Program Files folder (unless you prompt for elevation with UAC, but that's another topic...), your application will have a settings folder under %userprofile%\appdata\local
or %userprofile%\Local Settings\Application Data
depending on which version of Windows you're running, for settings that are user specific. If you store settings for all users, then they'll be in the corresponding folder under C:\users
or C:\Documents and Settings
for all user profiles (ex: C:\users\public\appdata\local
).
Where are my application settings stored exactly?
I hope I understand your question in the right way.
If you want to know, why settings are read from/written to the AppData
folder, then it's because of security/permission reasons.
When first starting your application, your initially application settings from app.config
file were copied to that folder. Your application will automatically work on that newly created file.
This is done, because it's a risk letting the user work on the "global" settings in your Program Files
folder, with which all your users will work. Think about what would happen, if a user only has permissions to read, but not to write to this file.
Where are application settings saved?
.NET has to do something special, it has to give you a guarantee that another program that also happens to have a "LastRuntime" setting doesn't overwrite the value that's stored for your program. To do that, it stores a user.config file in a directory that's hard to find back. It has a weirdo name, like
C:\Users\username\AppData\Local\WindowsFormsApplication1\WindowsFormsApplication1._Url_twchbbo4atpsvjpauzkgkvesu5bh2aul\1.0.0.0\user.config
Note how the project name is part of the path, that's one way to find it back. The unspeakable part of the name is a hash, created from various properties of your project that make your app unique enough to not collide with another .NET program, even if the name matches. Like your product name, company name, exe name, etcetera.
Note how the converse is true as well, changing such a property makes you lose your user.config file. So if "LastRuntime" is some kind of license metering value then using a setting isn't the best idea.
Store user settings file in executables directory
I added a custom Application Configuration File
called AppSettings.config
to my project and set its Copy to output
property to Copy if newer
(this copies the config file into the executables folder on building the project.
My settings must be classified as appSettings
, not applicationSettings
(non-editable) or userSettings
(stored in the users AppData
folder). Here's an example:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<!-- single values -->
<add key="Name" value="Chris" />
<add key="Age" value="25" />
<!-- lists, semi-colon separated-->
<add key="Hobbies" value="Football;Volleyball;Wakeboarding" />
</appSettings>
</configuration>
Look at the code below, how to access and modify them:
Configuration AppConfiguration =
ConfigurationManager.OpenMappedExeConfiguration(
new ExeConfigurationFileMap {ExeConfigFilename = "AppSettings.config"}, ConfigurationUserLevel.None);
var settings = AppConfiguration.AppSettings.Settings;
// access
var name = settings["Name"].Value;
var age = settings["Age"].Value;
var hobbies = settings["Hobbies"].Value.Split(new[]{';'});
// modify
settings["Age"].Value = "50";
// store (writes the physical file)
AppConfiguration.Save(ConfigurationSaveMode.Modified);
I used the built-in app.config
for default application settings and wanted to separate them from the editable global settings in AppSettings.config
. That's why I use a custom config file.
That's not directly an answer to the question, but it solves the problem on how to store and share editable application settings in custom configuration files.
Hope it helps any other users! :-)
Properties.Settings.Default.Save(); - Where is that file
On My Windows XP machine, the settings are saved in a file called user.config somewhere under either C:\Documents and Settings\<UserName>\Application Data\
or C:\Documents and Settings\<UserName>\Local Settings\Application Data\
Update:
On Windows Vista and later, the locations have changed to C:\Users\<UserName>\AppData\Roaming\
and C:\Users\<UserName>\AppData\Local\
Where does a console application REALLY store its settings
By default the settings in app.config
are also embedded into your code (just for those situations like what you describe... where you just have the EXE without any *.config
file). You can change this behavior by changing the GenerateDefaultValueInCode
for each setting.
There are two sections to the file... the application section has the read-only setting for the entire app. The user section has the starting default values of the settings that the user can change.
So, just to review:
app.config
= the design-time version of all the settings (it gets
renamed and copied tobin
)YourApplication.exe.config
= the run-time
version of the all of the settings%LOCALAPPDATA%\App\Version\user.config
= just the user portion of the
settings after they've made changes
Related Topics
System.Drawing Out of Memory Exception
Using Bindingoperations.Enablecollectionsynchronization
JSONconvert.Serializeobject Always Return {} in Xamarinforms
Datetime.Parse("2012-09-30T23:00:00.0000000Z") Always Converts to Datetimekind.Local
Upgrading Old Unity Code to Unity 5
How to Ensure a Timestamp Is Always Unique
Why Are Some Members Missing When Trying to Print an Object by Serializing to JSON
How to Get a Type's Alias Through Reflection
How to Set Web.Config File to Show Full Error Message
The Application Called an Interface That Was Marshalled for a Different Thread - Windows Store App
How to Compile a C# File with Roslyn Programmatically
What Is the Best Battleship Ai
When Is Readerwriterlockslim Better Than a Simple Lock
Sql: Update a Row and Returning a Column Value with 1 Query