我需要读取/写入与任何 exe 无关的配置文件。我正在尝试这个:
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");
}
不会抛出异常,但 fileEnvironment 始终为 null。这是文件内容:
<?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>
请有人带我走出荒野。在获得该部分的内容后,我也不知道如何编写或更改 NameValueCollection 中的条目。谢谢