给xml|web.config 增加节点和属性值

给xml|web.config 增加节点和属性值  

string basePathConfig = this.Request.PhysicalApplicationPath.ToString()+"Web.config";
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(basePathConfig); //加载你的XML文件
            XmlNode appSettings = xmlDoc.SelectSingleNode("/configuration/appSettings");//查找appSettings
            XmlElement adds=xmlDoc.CreateElement("add");//创建add节点
            adds.SetAttribute("key","test");
            adds.SetAttribute("value","testvalue");
            appSettings.AppendChild(adds);   //追加节点        
            xmlDoc.Save(basePathConfig);//保存文件
            Response.Write("success");成功提示

原文地址:https://www.cnblogs.com/bestsaler/p/1835513.html