软件编程
位置:首页>> 软件编程>> C#编程>> 使用C#实现读取系统配置文件的代码实例讲解

使用C#实现读取系统配置文件的代码实例讲解

作者:SmartMZ  发布时间:2023-02-18 10:36:56 

标签:C#,配置文件

需要添加引用,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>

  

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com