日期:2014-05-19  浏览次数:21118 次

如何在c#中指定程序使用哪个config文件?
我建立了app.config   app1.config   2个配置文件,我应该怎么指定某个特定程序使用哪个配置文件

------解决方案--------------------
ConfigurationSettings.AppSettings只能读取默认的App.config文件名;对于多个配置信息,你完全可以在 <appSettings> 节增加键值;
<appSettings>
   <add key= "ConnenctionString " value= "* " />
   <add key= "myValue " value= "* " />
......
</appSettings>

另外:在2.0中
ConfigurationFileMap fileMap = new ConfigurationFileMap();
fileMap.MachineConfigFilename = @ "你的配置文件路径\app1.config ";
Configuration config = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);

可以试试;

------解决方案--------------------
一个应用程序ConfigurationManager只读取默认app.config文件,特定的需要读取xml来取
------解决方案--------------------
1,合并2个配置文件,增加KEY 来实现。
2。保留一个基本信息的配置文件,然后自己实现设计一个XML文件,自己写方法封装
------解决方案--------------------
<XXXsection>

</XXXsection>
每个段对应一个解析类。解析他。就转成对象了。