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
.
In the Active solution configuration drop-down list, choose New. The New Solution Configuration dialog box opens. In the Name text box, enter a name for the new configuration. To use the settings from an existing solution configuration, in the Copy settings from drop-down list, choose a configuration.
In computing, configuration files (commonly known simply as config files) are files used to configure the parameters and initial settings for some computer programs.
Definition(s):The set of parameters that can be changed in hardware, software, or firmware that affect the security posture and/or functionality of the information system.
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
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With