11

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 4

10

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:

Read/Write App.config

Sign up to request clarification or add additional context in comments.

Comments

1

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

I believe this answer is more correct than the others. The Settings have built-in functionality for updating.
1

I was successful with using the method Justin Niessner suggested. One caveat to watch out for: When you are testing this in visual studio, the app.config itself won't be edited if you are debugging the application. The config file that is modified is the ProjectName.vshost.exe.Config

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.