给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");成功提示
本文介绍了一种在C#中通过加载XML文件的方式找到并修改Web.config文件中的appSettings部分的方法,具体展示了如何添加新的键值对。
239

被折叠的 条评论
为什么被折叠?



