手机
当前位置:查字典教程网 >编程开发 >C#教程 >使用linq to xml修改app.config示例(linq读取xml)
使用linq to xml修改app.config示例(linq读取xml)
摘要:复制代码代码如下:Configurationconfiguration=ConfigurationManager.OpenExeConfig...

复制代码 代码如下:

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<XElement> 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);

【使用linq to xml修改app.config示例(linq读取xml)】相关文章:

c# 引用类型和值类型

C#中FormClosing与FormClosed的区别详细解析

C#用Activex实现Web客户端读取RFID功能的代码

C#下解析HTML的两种方法介绍

C# 超高面试题收集整理

C# 获取属性名的方法

C# Word 类库的深入理解

c#二进制逆序方法详解

Http上传与Ftp上传的区别详解

在Winform动态启动、控制台命令行的方法

精品推荐
分类导航