zoukankan
html css js c++ java
动态编辑程序配置文件
Code
1
using
System;
2
using
System.Collections.Generic;
3
using
System.ComponentModel;
4
using
System.Data;
5
using
System.Drawing;
6
using
System.Linq;
7
using
System.Text;
8
using
System.Windows.Forms;
9
using
System.Xml;
10
11
namespace
WindowsFormsApplication1
12
{
13
public
partial
class
Form1 : Form
14
{
15
public
Form1()
16
{
17
InitializeComponent();
18
}
19
20
private
void
button1_Click(
object
sender, EventArgs e)
21
{
22
SaveConfig(
"
welcome
"
);
23
}
24
/**/
///
<summary>
25
///
设置配置文件
26
///
</summary>
27
///
<param name="ConnenctionString"></param>
28
private
void
SaveConfig(
string
ConnenctionString)
29
{
30
XmlDocument doc
=
new
XmlDocument();
31
//
获得配置文件的全路径
32
string
strFileName
=
AppDomain.CurrentDomain.BaseDirectory.ToString()
+
"
WindowsFormsApplication1.exe.config
"
;
33
doc.Load(strFileName);
34
//
找出名称为“add”的所有元素
35
XmlNodeList nodes
=
doc.GetElementsByTagName(
"
add
"
);
36
/**/
///
这里修改原结点
37
for
(
int
i
=
0
; i
<
nodes.Count; i
++
)
38
{
39
//
获得将当前元素的key属性
40
XmlAttribute att
=
nodes[i].Attributes[
"
name
"
];
41
42
//
根据元素的第一个属性来判断当前的元素是不是目标元素
43
if
(att.Value
==
"
my
"
)
44
{
45
//
对目标元素中的第二个属性赋值
46
att
=
nodes[i].Attributes[
"
connectionString
"
];
47
att.Value
=
ConnenctionString;
48
break
;
49
}
50
}
51
52
/**/
///
这里新加结点
53
nodes
=
doc.GetElementsByTagName(
"
connectionStrings
"
);
54
for
(
int
i
=
0
; i
<
nodes.Count; i
++
)
55
{
56
XmlNode nd
=
nodes[i];
57
XmlNode cnd
=
null
;
58
if
(nd.HasChildNodes)
59
{
60
cnd
=
nd.ChildNodes[i].Clone();
61
cnd.Attributes[
"
name
"
].Value
=
"
newvalue
"
;
62
cnd.Attributes[
"
connectionString
"
].Value
=
"
heelo!
"
;
63
}
64
65
66
nd.AppendChild(cnd);
67
68
}
69
//
保存上面的修改
70
doc.Save(strFileName);
71
}
72
73
}
74
}
75
这里和大家分享和学习如何学IT!
查看全文
相关阅读:
纷享销客公司产品能力学习笔记
有质量的两道面试题
java项目启动时执行指定方法
css银行卡号样式
swiper6使用鼠标滚轮失效退回swiper4即可
vue-swiper Demo
vue点击下载图片
跨域请求发送数据在body里,java后台接收
跨域,跨服务session获取不到,前后台不会传输Cookie,sessionId不一致
Windows下 redis命令及配置
原文地址:https://www.cnblogs.com/fuchifeng/p/1268275.html
最新文章
Python:利用Entrez库筛选下载PubMed文献摘要
Python:安装Bio库不成功,出现ModuleNotFoundError: No module named 'Bio'
Python:安装opencv出现错误Could not find a version that satisfies the requirement numpy==1.13.3 (from versions: 1.14.5, 1.14.6, 1.15.0rc2, 1.15.0, 1.15.1, 1.15.2, 1.15.3, 1.15.4, 1.16.0rc1, 1.16.0rc2,
Git 工作区、缓存区以及仓库内容比较方法
Spring(10)深入Spring 数据库事务管理(二)
Spring(10)深入Spring 数据库事务管理(一)
URL(UrI的子集,统一资源定位符)实现的具体方法
html标记的分类(转)
html,xml,xhmtl,sgml等等之间的关系*(转发)
两步解决VS Code运行Jupyter报错问题
热门文章
JS 实现数组交换位置
div 内元素的垂直居中
vscode调试vue项目
使用react-native-vector-icons(RN0.6+)
EChart 标题 title 样式,x轴、y轴坐标显示,调整图表位置等
.NetCore测试单元使用AutoFac依赖注入
.NetCore项目Linux部署总结
.NetCore 面试题
我的博客即将同步至 OSCHINA 社区
sql语句把符合条件的字段里面内容的部分内容替换
Copyright © 2011-2022 走看看