I need to read the web.config , outside the application folder (located in any other directory). I tried this code:
string filePath = @"C:\Users\Idrees\Downloads\New folder\Web.config"; Configuration c1 = ConfigurationManager.OpenExeConfiguration(filePath); var value1 = c1.AppSettings.Settings["Key1"].Value;
But this gives me an error:
The reference to the object is not installed in the instance of the object.
Because here c1.AppSettings is an object, but c1.AppSettings.Settings does not contain elements (hence, 0 Count). It does not load AppSettings keys. When you try to read any Key collection from Settings it gives this error.
Is there any way to download AppSettings keys from the web.config outside the application folder.
If I put the same file in the application folder, it will successfully read the keys.
This is my example configuration file contents:
<?xml version="1.0" encoding="utf-8"?> <configuration> <connectionStrings> </connectionStrings> <appSettings> <add key="Key1" value="Value1" /> <add key="Key2" value="Value2" /> <add key="Key3" value="Value3" /> </appSettings> </configuration>
I have a web application already running on my server. And I need to develop a small utility that should do some work in the database, and I donβt want to write db credentials or the connection string (and some other advanced application settings) in each application, I want it to read the same from the web .config.
source share