/// <summary>
/// 此方法用来修改配置内文件的内容
/// </summary>
/// <param name="AppKey">key</param>
/// <param name="AppValue">修改的值内容</param>
private static void NewMethod(string AppKey,string AppValue)
{
string fileName = "ToJsonConsoleApplication.exe.Config";
XmlDocument xDoc = new XmlDocument();
//获取可执行文件的路径和名称
xDoc.Load(System.AppDomain.CurrentDomain.BaseDirectory + fileName);
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(fileName);
}
C# 修改更新App.config文件无需重启服务
最新推荐文章于 2024-05-16 08:52:26 发布