作者:拍友2502905977 | 来源:互联网 | 2021-11-04 02:24
代码如下:
Configuration cOnfiguration= ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
configuration.AppSettings.Settings["节点名称"].Value ="0";
configuration.Save(ConfigurationSaveMode.Modified);
代码如下:
//获取config路径
string path = System.Windows.Forms.Application.ExecutablePath + ".config";
XDocument doc = XDocument.Load(path);
//查找所有节点
IEnumerable element = doc.Element("configuration").Element("appSettings").Elements();
//遍历节点
foreach (XElement item in element)
{
if (item.Attribute("key") != null && item.Attribute("key").Value == "节点名称")
{
if (item.Attribute("value") != null)
{
item.Attribute("value").SetValue(DateTime.Now.ToString("d"));
}
}
}
//保存
doc.Save(path);