How to read values from multiple Configuration file in c# within a single project?
See here.
Put this in your App.config
:
<appSettings file="accessLevel.config"/>
And then have another file called accessLevel.config
like this:
<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
<add key="TestSetting" value="TestValue"/>
</appSettings>
And then you can access your config values in code like this:
string value = ConfigurationManager.AppSettings["TestSetting"];
Make sure that accessLevel.config
is set to copy to the output directory (right click the file in Visual Studio -> Properties -> Copy To Output Directory -> Copy if Newer).
Praveen
user1671639 Thanks SO community for helping me with all my queries!! Question I like most: How do JavaScript closures work? Answer I like most: What's the difference between a URI and a URL? People whom I admire most in SO: Jon Skeet, Marc Gravell, David Thomas, T.J. Crowder, dystroy, PSL...
Updated on July 05, 2022Comments
-
Praveen almost 2 years
Here in my project I have two application configuration files called
app.config
andaccessLevel.config
. Now using theOpenExeConfiguration
I was able to access theapp.config.exe file
but not theaccessLevel.config
. Please help on this.The main reason I have 2 config files is to show the difference and make the code simple. I need to read the values from the
accessLevel.config
in myC#
code.Tried the below code but no use:
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.AppSettings.File = "App2.config";