This sample demonstrates how to read and write to an application's configuration file appSettings section.
.NET applications support custom XML configuration files out-of-the box. You simply add an app.config file to your solution via Project | Add New Item and select the Application Configuration File option. The item will be added to your bin directory each time you compile. You can then add your own settings to this file so that users or administrators can adjust an application's settings by simply adjusting a text file.
You can specifiy settings for individual controls that you want exposed via the configuration file. You simply add a Dynamic Property for any control value you want exposed. Examine the lblValue control for an example. Any of the dynamic property values defined in the appSettings section of configuration file will be loaded at runtime. You can access the values via the ConfigurationSettings.AppSettings. However, the NameValueCollection object exposed is read only. In addition, the settings are only loaded once at application startup.
If you want to be able to make changes to the file at runtime, you will need use the classes in the System.Xml namespace. This sample exposes two classes to let you do this:
AppSettings allows you to add, retrieve, update, and remove name/value pairs from the configuration file. It does this by wrapping access to the file via an XmlDocument instance. In addition it supports saving the changes manually or via an auto-save feature. Finally, the class implements IEnumerable to provide For..Each support.
Requires the Trial or Release version of Visual Studio .NET Professional (or greater).
Start the program and examine the data exposed. Change the file manually and then use the functions on the Custom tab to see the changes. Or, use the command options exposed under the Custom tab.