使用linq to xml修改app.config示例(linq读取xml)
时间:2022-11-22 22:01:28
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,xml
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
mybatis批量添加,批量更新之前如何判断是否已经存在
2022-01-03 20:33:38
![](https://img.aspxhome.com/file/2023/2/78962_0s.jpg)
c#如何使用 XML 文档功能
2023-12-25 03:44:33
Android中实现多行、水平滚动的分页的Gridview实例源码
2022-01-14 08:23:58
![](https://img.aspxhome.com/file/2023/0/111300_0s.gif)
Swing拆分窗格控件JSplitPane使用详解
2022-11-14 21:13:48
![](https://img.aspxhome.com/file/2023/0/63500_0s.jpg)
Spring Cloud基于zuul实现网关过程解析
2021-09-11 06:52:19
![](https://img.aspxhome.com/file/2023/2/108412_0s.png)
Flutter Dio二次封装的实现
2022-08-27 08:56:05
Android如何自定义按钮效果
2022-08-14 13:11:53
Java同步函数代码详解
2022-10-13 23:22:03
JVM之方法返回地址详解
2022-05-02 07:58:27
![](https://img.aspxhome.com/file/2023/0/88590_0s.png)
C# 对PDF文档加密、解密(基于Spire.Cloud.SDK for .NET)
2021-11-23 05:37:26
![](https://img.aspxhome.com/file/2023/4/100174_0s.png)
浅谈Java中方法参数传递的问题
2021-11-06 04:24:46
![](https://img.aspxhome.com/file/2023/4/60034_0s.png)
使用logback实现按自己的需求打印日志到自定义的文件里
2022-05-12 16:56:49
c# 多线程处理多个数据的方法
2023-12-01 17:45:58
![](https://img.aspxhome.com/file/2023/6/100126_0s.jpg)
解读JSONArray删除元素的两种方式
2022-10-31 11:40:50
C#实现3步手动建DataGridView的方法
2021-10-13 22:35:56
解析C#中委托的同步调用与异步调用(实例详解)
2022-12-24 19:06:47
Android代码实现新年贺卡动画示例详解
2022-09-11 00:28:49
Java 堆内存溢出原因分析
2023-06-27 08:34:23
![](https://img.aspxhome.com/file/2023/6/72626_0s.png)
Kotlin数据容器深入讲解
2022-03-28 05:19:34
![](https://img.aspxhome.com/file/2023/2/116032_0s.png)
android6.0权限动态申请框架permissiondispatcher的方法
2023-07-31 10:51:57