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
).
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 is the data for Properties.Settings.Default saved?
Since you selected user scope, they are saved in each user profile directory, more specifically, inside the AppData
folder of the user profile in a file named user.config
.
The full path is dependent of the application.
In Windows 7 without roaming profile and with an Windows Forms Application named Example.Settings.CustomClass
I'm getting the following folder:
C:\Users\[user]\AppData\Local\Microsoft\Example.Settings.CustomCl_Url_3qoqzcgn1lbyw2zx3oz1o3rsw2anyjsn\1.0.0.0
Also note that they are saved taking in consideration the version of your application and that the values stored in App.config
are the default values used for a new user.
Properties.Settings will not be saved
It definitely works. Try this:
public void Test(int value)
{
Properties.Settings settings = Properties.Settings.Default;
MessageBox.Show("Last SliderWidth = " + settings.SliderWidth.ToString());
settings.SliderWidth = value;
settings.Save();
}
But the saved value won't be reflected in the Designer window you are showing in your screen shot. Those are the initial default values.
Force all user settings to save
The way I managed to solve it was by modifying some existing code I had in a different project to handle version upgrades.
When the program runs:
if (PropertiesSettings.Default.UpgradeRequired)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.UpgradeRequired = false;
Properties.Settings.Default.Save();
reloadSettings();
}
// Assign settings to themselves and save
// This keeps settings the same as the defaults even when upgrading but ensures all settings appear in the config file
private void reloadSettings()
{
Properties.Settings.Default.Setting1 = Properties.Settings.Default.Setting1;
Properties.Settings.Default.Setting2 = Properties.Settings.Default.Setting2;
//etc
Properties.Settings.Default.Save();
}
The UpgradeRequired
setting should be set to True by default, so a new version with no config will be forced to run the first if statement. The .NET Properties.Settings.Default.Upgrade();
should then take care of finding old config files and loading the old settings.
Related Topics
Append a Lists Contents to Another List C#
How to Write Data on Multiple Lines But Within the Same Cell of Csv
How to Add Json to Restsharp Post Request
Check for Special Characters (/*-+_@&$#%) in a String
Get the Pre-Last Element of a String Split by Spaces
Regex Match Keywords That Are Not in Quotes
How to Modify a Getter and Setter, to Handle a Null Reference Exception
C#, Access Child Properties from Parent Reference
How to Get Nested Json Values in C#
How to Get Column Names of Table At Runtime in C#
How to Create ASP.NET Identity Tables in an Already Created Database Using Code First
How to Add a Run Button and Compile Button on the Toolbar in Visual Studio
Reading from Excel File Using Closedxml
Automapper - Map Using the Same Source and Destination Object Types
How to Implement Async Task to Fetch Data from Database Using Async and Await
Linq: Select an Object and Change Some Properties Without Creating a New Object