0

I have loaded the default App.config file in my solution and I'm able to access stored variables from it.

XML

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="foo" value="bar"/>
  </appSettings>
</configuration>

C#

Configuration configManager = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
KeyValueConfigurationCollection config = configManager.AppSettings.Settings;
string foo = config["foo"].Value;

Now I have created another configuration file to store variables for another part of my solution, but I can't figure out how to load it the same way with ConfigurationManager.

Configuration config2 = ConfigurationManager.OpenExeConfiguration("path/to/config.config");
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
ryansin
  • 1,735
  • 2
  • 26
  • 49

1 Answers1

1

Perhaps you are looking for this:

ExeConfigurationFileMap exeConfigurationFileMap = new ExeConfigurationFileMap();
exeConfigurationFileMap.ExeConfigFilename = "your file path here";
Configuration customConfig = ConfigurationManager.OpenMappedExeConfiguration(exeConfigurationFileMap, ConfigurationUserLevel.None);
mason
  • 31,774
  • 10
  • 77
  • 121
danish
  • 5,550
  • 2
  • 25
  • 28