C# READING CONFIGURATION SETTINGS

Ashish Pandey

Total Post:128

Points:898
Posted by  Ashish Pandey
C# 
C#
 1446  View(s)
Ratings:
Rate this:

I have a C# class library A which has some configuration settings in its App.config I access them with

Method1()

{

string connectionString = ConfigurationManager.AppSettings["ConnectionString"];

}

But when I call Method 1() from my ASP Web project B, it cannot find the configurations settings in the Class library A

Any idea what is happening here?

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: C# Reading Configuration settings

    Hi Ashish,


    I believe you can use OpenExeConfiguration to do this:

    string exePath = "<full path and name of the app .exe file>";

    System.Configuration.Configuration otherConfig =

         ConfigurationManager.OpenExeConfiguration(exePath);

    You could put the path of the other .exe in the web app's web.config (for instance, in the appSettings section), and read it from there, which would be better than hard-coding it here.

    to view the appSettings in that config file:

    AppSettingsSection otherAppSettings = otherConfig.AppSettings;

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!