现在的位置: 首页 > 综合 > 正文

C#修改app.config配置文件信息

2013年10月04日 ⁄ 综合 ⁄ 共 576字 ⁄ 字号 评论关闭

//更新app.config的函数

private   void   UpdateConfig(string   Xvalue)
{   
    XmlDocument   doc   =   new   XmlDocument();   
    doc.Load(Application.ExecutablePath+".config");   
    XmlNode   node   =   doc.SelectSingleNode(@"//add[@key='ServerName']");   
    XmlElement   ele   =   (XmlElement)node;   
    ele.SetAttribute("value",Xvalue);   
    doc.Save(Application.ExecutablePath+".config");     
}   

//配置文件的源文件

  <?xml   version="1.0"   encoding="utf-8"   ?>   
  <configuration>   
  <appSettings>   
  <add   key="ServerName"   value=""/>   
  </appSettings>   
  </configuration>   

抱歉!评论已关闭.