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

//更新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> 

posted @ 2009-04-08 08:19  scgw  阅读(1564)  评论(0编辑  收藏  举报