日期:2014-05-17 浏览次数:20921 次
        public static void SetValue(string AppKey, string AppValue)
        {
            XmlDocument xDoc = new XmlDocument();
            //加载app.config
            xDoc.Load("..\\..\\app.config");
            XmlNode xNode = xDoc.SelectSingleNode("//connectionStrings");
            XmlElement oldElement = (XmlElement)xNode.SelectSingleNode("//add[@name='" + AppKey + "']");
            if (oldElement != null)
            {
                oldElement.SetAttribute("connectionString", AppValue);
            }
            else
            {
                XmlElement newElement = xDoc.CreateElement("add");
                newElement.SetAttribute("name", AppKey);
                newElement.SetAttribute("connectionString", AppValue);
                xNode.AppendChild(newElement);
            }
            xDoc.Save("..\\..\\app.config");
        }