我需要读取/写入与任何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始终为空。这里是文件内容:
<?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中的条目,当我得到该部分的内容后。 感谢
你有你的解决方案的几个项目?项目中的配置文件是否是您的启动应用程序? – Mharlin
是的,将会有5个项目,其中三个需要访问这个配置文件。 – JimBoone
这是一个与任何exe无关的配置文件。我认为我可以将其用作通用配置平台。应用程序必须从一个主要的exe或运行每个项目的控制台应用程序运行。 – JimBoone