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>