Reputation: 1817
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");
Upvotes: 0
Views: 212
Reputation: 5600
Perhaps you are looking for this:
ExeConfigurationFileMap exeConfigurationFileMap = new ExeConfigurationFileMap();
exeConfigurationFileMap.ExeConfigFilename = "your file path here";
Configuration customConfig = ConfigurationManager.OpenMappedExeConfiguration(exeConfigurationFileMap, ConfigurationUserLevel.None);
Upvotes: 1