A configuration file holds information that is used by applications when they are executed. The main reason for using configuration files is to allow specific settings to be changed without the need to recompile the application.
Types of information contained in configuration files include connection strings, directory paths and static IP addresses.
In .NET information can be read from configuration files via the System.Configuration namespace. The config files need to be added to the .NET project as they are not defaulted. Windows applications use a file called App.Config and web applicaitons use a file called Web.Config. Once the file is added to the project, the AppSettingsReader class is used to access the appropriate file.
AppSettingsReader Class – Common Methods
- GetValue
- GetType
- GetHashCode
All methods for the AppSettingsReader class can be found here.
The GetValue() method accepts two arguments, the key for the value and the type of value. GetValue() returns as an object, so there will be a need to cast the return value.

Below are sample programs that demonstrate how information can be read from a configuration file. Sample config files are also included.
App.Config File and Program Listing
Result

Web.Config File and Program Listing
Result

There are many uses for .NET configuration files. If you take a look at the System.Configuration namespace and it’s plethora of classes, you will see that I have only scratched the surface.
[-- Related Links --]
Code Project – Custom app.config
C# Corner – Using Web.Config in ASP.NET and ASP
OdeToCode – AppSettings In web.config