Application Configuration Settings in .NET

Application Configuration Settings in .NET

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" ?>
<configuration>
  <appSettings>
    <add key="ApplicationName" value="MyApplication"/>
    <add key="DefaultLanguage" value="English"/>
  </appSettings>
</configuration>

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"];
READ ALSO:  Introduction to LINQ to SQL

This Post Has 2 Comments

  1. Avatar
    Somil

    How could you use Configurationmanager class in Windows application c#.

  2. Avatar
    pimsainnum

    Thank you share .
    This code to help me for solve.

    So cool.

Leave a Reply