怎么去修改啊? 怎么修改失败

解决方案 »

  1.   

    protected string GetValue(string AppKey)
            {
                try
                {
                    string AppKeyValue;
                    AppKeyValue = (string)System.Configuration.ConfigurationManager.AppSettings[AppKey];
                    return AppKeyValue;
                }
                catch (Exception ex)
                {
                    return "";
                }
            }        protected bool SetValue(string AppKey, string AppValue)
            {
                try
                {
                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(AppDomain.CurrentDomain.BaseDirectory + "/" + AppConfigName);
                    XmlNode xNode;
                    XmlElement xElem1;
                    XmlElement xElem2;
                    xNode = xDoc.SelectSingleNode("//appSettings");
                    xElem1 = (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(AppDomain.CurrentDomain.BaseDirectory + "/" + AppConfigName);
                }
                catch
                {
                    return false;
                }
                return true;
            }试试看
      

  2.   

    其实就是跟操作XML文件差不多。
      

  3.   

    neng 给点操作XML de 例子吗?
    呵呵,谢啦