This post shows a console application that uses the ConfigurationManager class. The code example extends what is already in the current documentation to demonstrate the use of this class. The example has been built using Microsoft Visual Studio 2008 and the .NET Framework 3.5.
The ConfigurationManager class enables a Web or Windows application to access machine, application, and user configuration files. The name and location of the configuration files depend on whether you are working with a Web application or a Windows console application. For more information, see Application Configuration Files.
You can use this example to build a console application by simply replacing the program file in a console project. For information about how to build a console application, see How to: Create a Console Application.
Note To compile this example, you must add a reference to the System.Configuration assembly to the project.
To get the example source code, click one of the following links
· Using ConfigurationManager (C#).
· Using ConfigurationManager (VB.NET).
We appreciate your comments and feedback.
The example shows how to build a console application that exercises the main capabilities of the ConfigurationManager class. The example works with a custom configuration section that stores color information for the background and foreground of the console window. The custom configuration section lets you do the following:
The example contains the following classes:
UsingConfigurationManager performs the following tasks:
· Gets the roaming configuration file associated with the application. · Gets the application configuration file associated with the application. · Accesses a specified configuration file through mapping. · Accesses the machine configuration file through mapping. · Reads a specified configuration section. · Reads the connectionStrings section. · Reads or writes the appSettings section.
· Gets the roaming configuration file associated with the application.
· Gets the application configuration file associated with the application.
· Accesses a specified configuration file through mapping.
· Accesses the machine configuration file through mapping.
· Reads a specified configuration section.
· Reads the connectionStrings section.
· Reads or writes the appSettings section.
For a complete example, see the attached files.
We look forward to your comments and feedback.
Michael Miele
ASP.NET User EducationThis posting is provided "AS IS" with no warranties, and confers no rights.
Give Your Feedback on the Documentation
Help us improve the developer documentation by taking the Visual Studio and .NET Framework Content Survey. This survey will give us a better understanding of the type of applications you are developing as well as how you use Help and how we can improve it. The survey takes only 10 minutes, and we appreciate your feedback.