Application Configuration Settings in .NET

You are currently viewing 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:  10 Best Podcasts .NET Developers will Love in 2021

This Post Has 2 Comments

  1. Somil

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

  2. pimsainnum

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

    So cool.

Leave a Reply