var xDoc = new System.Xml.XmlDocument();
xDoc.Load(Application.ExecutablePath + ".config"); //加载配置文件位置(应用程序.exe.config)
var xNode = xDoc.SelectSingleNode("//appSettings"); //配置文件节点
var xElem1=(System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='serverAddr']");
if (xElem1 != null) xElem1.SetAttribute("value", this.txtServerAddr.Text.Trim());
var xElem3=(System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='databaseName']");
if (xElem3 != null) xElem3.SetAttribute("value", this.txtDataBaseName.Text.Trim());
var xElem4=(System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='databasePwd']");
if (xElem4 != null) xElem4.SetAttribute("value", this.txtDataBasePwd.Text.Trim());
var xElem5=(System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='loactionName']");
if (xElem5 != null) xElem5.SetAttribute("value", this.txtLocationName.Text.Trim());
xDoc.Save(Application.ExecutablePath + ".config");
//配置文件信息
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key ="serverAddr" value="192.168.0.59" />
<add key="databaseName" value="ZTXA" />
<add key="databasePwd" value="123456789" />
<add key="loactionName" value="北京" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
</configuration>