赞
踩
{
//读取当前exe的config:App.config
//读取appSettings节点里的数据
NameValueCollection nameValues = ConfigurationManager.AppSettings;//读取当前exe的config:App.config
//使用exe路径
Configuration configuration = ConfigurationManager.OpenExeConfiguration(Assembly.GetEntryAssembly().Location);AppSettingsSection group1 = (AppSettingsSection)group.Sections.Get("Group1");
Console.WriteLine(str);
//改变值
group1.Settings["Key"].Value = "ChangedValue";
// 保存
configuration.Save();
//读取dll的config文件:TestDll.dll.config
Type tp = typeof(Class1);}
App.config文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="Group">
<section name="Group1" type="System.Configuration.AppSettingsSection"/>
<section name="Group2" type="System.Configuration.AppSettingsSection"/>
</sectionGroup>
</configSections>
<Group>
<Group1>
<add key ="Key" value="10"/>
</Group1>
<Group2>
<add key ="Key" value="10"/>
</Group2>
</Group>
<appSettings>
<add key="Key" value="Value"/>
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
TestDll.dll.config文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="Group">
<section name="SubGroup" type="System.Configuration.AppSettingsSection"/>
</sectionGroup>
</configSections>
<Group>
<SubGroup>
<add key="TestKey" value="TestValue"/>
</SubGroup>
</Group>
</configuration>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。