Reputation: 155
I'm trying to use the application setting in my c# project. However, Properties.Settings.Default.Reset() actually sets all properties to their system defaults (a String will be set to null and not the value i set as base).
Is there a way to set default values for properties so that i can call a method to set them to default?
Edit : The question concerns setting to default individual properties, not all of them together.
Upvotes: 0
Views: 2043
Reputation: 421
You can specify defaults for user settings from Visual Studio, in the Properties window of the project, in the Settings tab. Just enter something in the Value column.
The values you specify get saved in app.config, in the userSettings
section (you can edit them there, too), and they will be used when calling Properties.Settings.Default.Reset()
.
To understand what happens: when you call Save()
, the current values of the user settings are saved in a file under the user profile folder in Windows, and when you call Reset()
the values from the app.config file from the application folder are used to overwrite them.
If you just want to reset an individual setting (SomeSetting) to its default, you could do:
Settings.Default.SomeSetting = Settings.Default.Properties["SomeSetting"].DefaultValue;
Settings.Default.Save();
Upvotes: 3