How do I get my .NET Application's Configuration Settings?

Your .NET Application Configuration File holds application specific information. Information stored consists of information stored by the VS.NET IDE such as CLR (Common Language Runtime) version and dependent assembly information.

You can also store your own application settings there as you would in an .INI file in VB6. The VS.NET IDE allows you to edit this file and enter your information. This page shows how to retrieve your custom application setting data. To see how to retrieve data stored by the VS.NET IDE click here.

The config file is an XML file having the same name as your executable with an additional .config extension. The .NET Framework provides the System.Configuration.ConfigurationSettings.AppSettings namspace which lets you to retrieve appSettings elements from the configuration file. Data is stored in key/value pairs as shown in this sample .config file:

        <add key="MyDatabaseConnectionString" value="Provider=Microsoft.Jet,..."/>
        <add key="MyExcelFileName" value="C:\...\myWorksheet.xls"/>

From VB.NET you can read this using:

    Dim aConfig As Configuration.ConfigurationSettings
    Dim aExcelFile As String = aConfig.AppSettings("MyExcelFileName")

In C# you can write:

    using System.Configuration;

    string aExcelFile;
    aExcelFile = ConfigurationSettings.AppSettings.Get("MyExcelFileName");

About TheScarms
About TheScarms

Sample code
version info

If you use this code, please mention ""

Email this page

© Copyright 2024 TheScarms
Goto top of page