使用C#实现读取系统配置文件的代码实例讲解
更新时间:2015年12月27日 16:56:12 作者:SmartMZ
这篇文章主要介绍了使用C#实现读取系统配置文件的代码实例,使用到了ConfigurationManager类,需要的朋友可以参考下
需要添加引用,System.Configuration;
写系统配置文件:
Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (addrService != "")
{
cfa.AppSettings.Settings["WebServiceUrl"].Value = addrService;
}
if (setLogin != "")
{
cfa.AppSettings.Settings["LoginServerUrl"].Value = setLogin;
}
if (mapPath != "")
{
cfa.AppSettings.Settings["InitMapPath"].Value = mapPath;
}
cfa.Save(ConfigurationSaveMode.Modified);
//重新加载配置文件
ConfigurationManager.RefreshSection("appSettings");
读:
<pre name="code" class="csharp"> string value = ConfigurationSettings.AppSettings["InitMapPath"];</pre> <pre></pre> <p></p> <pre></pre> <br> <br> <p></p> <p><br> </p>
相关文章
C#中IEnumerable、ICollection、IList、List之间的区别
这篇文章主要介绍了C#中IEnumerable、ICollection、IList、List之间的区别,本文分别分析了它的实现源码,从而总结出了它们之间的关系和不同之处,需要的朋友可以参考下2015-06-06
Unity的IFilterBuildAssemblies实用案例深入解析
这篇文章主要为大家介绍了Unity的IFilterBuildAssemblies实用案例深入解析,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2023-05-05


最新评论