A Guided Garden Stroll through the .NET Framework Class Library

Namespace: SYSTEM.CONFIGURATION

● I am the Configuration Namespace. My most famous class is called ConfigurationSettings.

The ConfigurationSettings class is most useful any time you want to retrieve dynamic properties that affect how your application runs after it’s been compiled and deployed.

The most common use of dynamic properties is for recording a database connection string. Using a simple XML format, you can record your database connection string, including username and password (if required) using an associated key value, that you make up, in your application’s config file. Every executable application can have one and only one config file. For Web Applications, this would be the Web.config file located in the root folder of your ASP.NET application. For Windows and Console applications, this would be a text file you create called "YourApplicationName.exe.config" that is placed in the application’s startup folder.

Since the values in the config file are cached after the first lookup, the retrieval of information via ConfigurationSetings.AppSettings is very efficient.

To get a value, such as a connection string, from the .config file, simply call the static property ConfigurationSettings.AppSettings("MyConnectionString"), where MyConnectionString is the key you defined.

To put a new value in the .config file, simply add a section tag called appSettings and enter <add key="connectionString" value="your connection string goes here" />

.NET Dynamic component properties also get placed in this file. For example, when you consume a Web Service in your application, you should dynamically declare the Web Service source in your code. This is easily done in the property pages of the Web Service when you attach the remote service to your application. By doing this, you can now easily change the source of a Web Service your app calls by updating the Web.config file without having to re-compile and re-deploy your application.

Be sure to secure your config file using system ACL settings since anyone can view or change settings by simply using notepad.

See "Introduction to Dynamic Properties" in MSDN for more information about configuration settings.

www.Orbonyx.com