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
  • 38,279
  • 56
  • 171
  • 280
ryansin
  • 1,654
  • 2
  • 21
  • 43

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
  • 30,041
  • 9
  • 73
  • 113
danish
  • 5,436
  • 2
  • 24
  • 28