I have configuration values saved in an app.config. I want to create a WinForms application which shows all the AppSettings values in a form. The user should be able to change the settings values and save them back to the app.config.
4 Answers
As long as your values are in the appConfig section of the app.config file, you can simply use System.Configuration.ConfigurationManager.
ConfigurationManager.AppSettings - MSDN
Here's an old blog post explaining EXACTLY how to do what you're looking for:
Comments
If you store the settings using the Settings.settings file in the Properties folder you can just do:
Properties.Settings s = new Properties.Settings(); And then all the settings will be properties of s (you can define them as a specific type even) and if they're set as user settings you can change them. Just call Reload or Save on the instance of Settings to read/store from/to disk.
1 Comment
Settings have built-in functionality for updating.Have a look at System.ConfigurationManager. There's a huge example on the MSDN page showing almost all the necessary functionality to configure, alter, save, etc, all in the language of your choice.
The ConfigurationManager class includes members that enable you to perform the following tasks:
- Read a section from a configuration file.
- Read and write configuration files as a whole
- Support configuration tasks.