I need to read/write to a config file not related to any exe. I'm trying this:
var appConfiguration = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap() { ExeConfigFilename = "SlamDunkSuper.config" }, ConfigurationUserLevel.None);
if(appConfiguration == null) {
//Configuration file not found, so throw an exception
//TODO: thow an exception here
} else {
//Have Configuration, so work on the contents
var fileEnvironment = appConfiguration.GetSection("fileEnvironment");
}
No exception is thrown, but fileEnvironment is always null. Here is the file contents:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="fileEnvironment" type="System.Configuration.NameValueSectionHandler"/>
</configSections>
<fileEnvironment>
<add key="DxStudioLocation" value="123456"/>
</fileEnvironment>
</configuration>
Someone please lead me out of the wilderness. I also don't know how to write, or change, an entry in the NameValueCollection, after I get the contents of the section. Thanks
You can globalize AppSettingsSection with some minor adjustments:
Consume with: