zoukankan
html css js c++ java
读写xml文件结点值
public
static
void
UpdateConfig(
string
item,
string
itemvalue)
{
try
{
//
将连接字符串写入Web.config
System.IO.FileInfo fileInfo
=
new
FileInfo(AppDomain.CurrentDomain.BaseDirectory
+
"
DataBase.xml
"
);
if
(
!
fileInfo.Exists)
MessageBox.Show(
"
can't find the app.config
"
);
XmlDocument doc
=
new
XmlDocument();
doc.Load(fileInfo.FullName);
//
doc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
bool
foundIt
=
false
;
string
connString
=
itemvalue;
string
enCS
=
connString;
//
SecurityHelper.EncryptDBConnectionString(connString);
XmlNode no
=
doc.SelectSingleNode(
"
//appSettings/add[@key='
"
+
item
+
"
']
"
);
if
(no
!=
null
)
{
no.Attributes.GetNamedItem(
"
value
"
).Value
=
enCS;
foundIt
=
true
;
}
if
(
!
foundIt)
MessageBox.Show(
"
can't find the connString setting
"
);
doc.Save(fileInfo.FullName);
}
catch
(Exception ex)
{
StreamWriter w
=
new
StreamWriter(AppDomain.CurrentDomain.BaseDirectory
+
"
log.txt
"
,
true
);
w.WriteLine(
"
===in updata connstring=tjtj=====
"
);
w.WriteLine(ex.ToString());
w.WriteLine(ex.StackTrace);
w.Close();
}
}
public
static
string
LoadConfig(
string
item)
{
string
reval
=
""
;
try
{
//
将连接字符串写入Web.config
System.IO.FileInfo fileInfo
=
new
FileInfo(AppDomain.CurrentDomain.BaseDirectory
+
"
DataBase.xml
"
);
if
(
!
fileInfo.Exists)
MessageBox.Show(
"
can't find the app.config
"
);
XmlDocument doc
=
new
XmlDocument();
doc.Load(fileInfo.FullName);
//
doc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
bool
foundIt
=
false
;
XmlNode no
=
doc.SelectSingleNode(
"
//appSettings/add[@key='
"
+
item
+
"
']
"
);
if
(no
!=
null
)
{
reval
=
no.Attributes.GetNamedItem(
"
value
"
).Value;
foundIt
=
true
;
}
if
(
!
foundIt)
MessageBox.Show(
"
can't find the connString setting
"
);
}
catch
(Exception ex)
{
StreamWriter w
=
new
StreamWriter(AppDomain.CurrentDomain.BaseDirectory
+
"
log.txt
"
,
true
);
w.WriteLine(
"
===in updata connstring=tjtj=====
"
);
w.WriteLine(ex.ToString());
w.WriteLine(ex.StackTrace);
w.Close();
}
return
reval;
}
查看全文
相关阅读:
组织机构数据隔离(上级可看下级,同级屏蔽)的高效实现思路
.NET Core 3.x 基于AspectCore实现AOP,实现事务、缓存拦截器
.NET Core 3.x 基于Autofac的AOP缓存
Web开发中【密码加密】详解
python多线程 DBUtils操作数据库
处理MariaDB Galera cluster初始化和启动报错两例
搭建MariaDB Galera Cluster集群 10.3.8
AzureWeb应用作为客户端携带证书访问其他链接办法
CTF
[KuangBin专题四]Silver Cow Party
原文地址:https://www.cnblogs.com/lidune/p/546752.html
最新文章
快速搭建ELK日志分析系统
SpringBoot2.0集成Quartz
SpringBoot使用Elasticsearch之RestHighLevelClient
ElasticSearch入门到精通详解
Pinpoint安装采集docker的springboot
Dockerfile之COPY和ADD区别
匿名内部类使用的外部变量必须是final
快速入门使用tikz绘制深度学习网络图
使用关键点进行小目标检测
【资源】CenterNet原理与代码解析
热门文章
【从零开始学CenterNet】7. CenterNet测试推理过程
用不等距离的方式获取两个字符的编辑距离
获取正负夹角
二分法搜索范围
后缀数组增量包算法
比较两字符的相等长度和大小
文本分割-隐马尔可夫模型
马尔科夫模型推算股票
文字分词 隐马尔可夫模型-JavaScript
C# 实现Eval(字符串表达式)的三种方法
Copyright © 2011-2022 走看看