#region 修改APPconfig设置
public static void SetConfigValue(string AppKey, string AppValue)
{
System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
xDoc.Load(Application.StartupPath + "//LedInfoSystem.dll.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(Application.StartupPath + "//LedInfoSystem.dll.config");
}
public static string GetConfigValue(string AppKey)
{
System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
xDoc.Load(Application.StartupPath + "//LedInfoSystem.dll.config");
System.Xml.XmlNode xNode;
System.Xml.XmlElement xElem1;
xNode = xDoc.SelectSingleNode("//appSettings");
xElem1 = (System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
string appValue = xElem1.Value;
return appValue;
}
public static void SetWebServiceAddressValue(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;
xNode = xDoc.SelectSingleNode("//client");
xElem1 = (System.Xml.XmlElement)xNode.SelectSingleNode("//endpoint[@address]");
if (xElem1 != null) xElem1.SetAttribute("address", AppValue);
xDoc.Save(System.Windows.Forms.Application.ExecutablePath + ".config");
}
public static string GetWebServiceAddressValue()
{
System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
xDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config");
System.Xml.XmlNode xNode;
System.Xml.XmlElement xElem1;
xNode = xDoc.SelectSingleNode("//client");
xElem1 = (System.Xml.XmlElement)xNode.SelectSingleNode("//endpoint[@address]");
string strAddress = xElem1.GetAttribute("address").ToString();
return strAddress;
}
#endregion
C# 修改APPconfig设置
最新推荐文章于 2024-08-22 10:29:32 发布