12

Here in my project I have two application configuration files called app.config and accessLevel.config. Now using the OpenExeConfiguration I was able to access the app.config.exe file but not the accessLevel.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 my C# code.

Tried the below code but no use:

System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); 
config.AppSettings.File = "App2.config";
0

1 Answer 1

28

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).

Sign up to request clarification or add additional context in comments.

6 Comments

Should I have this line in app.config.exe?
Have edited and fixed up - see if you can get that working? Is it appSettings you are trying to move into another file, or some other config section? Either way, the same principle applies.
@Aniket Done. sorry, I missed to pick it on the right time.
Please note that the second config (accessLevel.config) begins with <appSettings /> element, not default <configuration /> element. I spend about 10 minut before i realize this ;)
How is this "reading values from multiple Configuration files"? Only values from accessLevel.config are read, via app.config...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.