手机
当前位置:查字典教程网 >编程开发 >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#下解析HTML的两种方法介绍

C#难点逐个击破(5):类的访问类型

C#基础:基于const与readonly的深入研究

c# 引用类型和值类型

深入分析C#键盘勾子(Hook)拦截器,屏蔽键盘活动的详解

c#使用linq技术创建xml文件的小例子

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

使用C# Winform应用程序获取网页源文件的解决方法

C#读写操作app.config中的数据应用介绍

C#中把日志导出到txt文本的简单实例

精品推荐
分类导航