1.winform中设置两个textbox 一个用于获取key 一个用于获取value 调用是传递到下面的方法中
运行窗体时事件下出发将值写入到*.exe.config中 不过需要重启客户端才能生效 问题放这 看以后能不能解决。
public static void SetValue(string AppKey, string AppValue)
{
System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
xDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config");
System.Xml.XmlNode xNode;
System.Xml.XmlElement xElem1;
System.Xml.XmlElement xElem2;
xNode = xDoc.SelectSingleNode("//appSettings");
xElem1 = (System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
if (xElem1 != null) xElem1.SetAttribute("value", AppValue);
else
{
xElem2 = xDoc.CreateElement("add");
xElem2.SetAttribute("key", AppKey);
xElem2.SetAttribute("value", AppValue);
xNode.AppendChild(xElem2);
}
xDoc.Save(System.Windows.Forms.Application.ExecutablePath + ".config");
}
private void button1_Click(object sender, EventArgs e)
{ //this.key = "StuMisConnctionStr";
//this.value = "server=" + this.serverIP.Text + ";database=" + this.ServerName.Text + ";integrated security=false;uid=" + this.name.Text + ";pwd=" + this.Pwd.Text + "";
//SetValue(key, value);
}