Application Configuration Settings in .NET

Waqas Anwar
08 April 2008

Saving and restoring application settings outside source code is crucial part of any software application. .NET Framework provides very simple solution for saving application settings in .config files. Framework also provides classes to read these settings in .NET application in a very easy way. In the following tutorial, I will show you how you can store and retrieve application settings stored in App.config file in .NET windows application using C#.

First step to store application settings is to add App.config file in the project. In App.config file you can store application settings as shown below.

<?xml version="1.0" encoding="utf-8" ?>
    <add key="ApplicationName" value="MyApplication"/>
    <add key="DefaultLanguage" value="English"/>

Once your settings are stored in App.config file you can read these settings in .NET application by using System.Configuration.ConfigurationManager class as following code demonstrates.

string appName = ConfigurationManager.AppSettings["ApplicationName"];
string appLanguage = ConfigurationManager.AppSettings["DefaultLanguage"];