views:

632

answers:

3

I have some of the values saved in app.config file, I want to create a WinForms application which shows all the AppSettings values in a Form.

In the form user can change the settings values, after making changes the user can press the Save button and on this I want to save all the values back to the app.config file.

Is there any way to do that in C#?

A: 

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.
Kyle Rozendo
+3  A: 

As long as your values are in the appConfig section of the app.config file, you can simply use System.ConfigurationManager.

ConfigurationManager.AppSettings - MSDN

Here's an old blog post explaining EXACTLY how to do what you're looking for:

Read/Write App.config

Justin Niessner
A: 

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.

ho1