Search Amazon:

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:

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

 

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");

Sign In
  User Id 
  Password 


Submit Your Own Code and Articles




About TheScarms
About TheScarms

Ask me your programming questions

I read every email and answer all I can.

User Feedback: Be the first to add a comment! Items to Show:     

     
You must log in to post feedback.
Comment:    
 

If you use this code, please mention "www.TheScarms.com"

Email this page


TheScarms AppSentinel lets you securely copy protect and create evaluation versions of your software

TheScarms(tm) AppSentinel lets you quickly and easily create evaluation versions of your software and stop unauthorized copying and unregistered use of your programs!

Get your free
trial copy today!


      The World's Number 1 Web Host

© Copyright 2008 TheScarms