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;
}
查看全文
相关阅读:
c#透明TextBox
Twitter的分布式自增ID算法snowflake(雪花算法)
关于权限设计的一点建议
关于下载地址权限控制的一点问题解决方法
数据结构_总结
输出全排列输出
数据结构_图总结
n个括号对的所有可能情况
根据表达式序列(前缀、中缀、后缀)构建表达式树
Java finally语句是在try或catch的retrurn之前还是之后执行
原文地址:https://www.cnblogs.com/lidune/p/546752.html
最新文章
postman(五):在不同接口之间传递数据
postman(四):添加变量
postman(三):添加断言
postman(二):使用postman发送get or post请求
(九)c#Winform自定义控件-树-HZHControls
(八)c#Winform自定义控件-分割线-HZHControls
(七)c#Winform自定义控件-进度条-HZHControls
(六)c#Winform自定义控件-单选框-HZHControls
(五)c#Winform自定义控件-复选框-HZHControls
(四)c#Winform自定义控件-选择按钮组-HZHControls
热门文章
(三)c#Winform自定义控件-有图标的按钮-HZHControls
(二)c#Winform自定义控件-按钮-HZHControls
(一)c#Winform自定义控件-基类控件-HZHControls
c# Winform 加载窗体
c# winform 窗体失去焦点关闭(钩子实现)
c# winfrom 更新控件时停止刷新,解决闪烁问题
c# Winform 继承窗体 无法拖动修改控件大小
c# 查询本机可用的代理ip
c# winform快捷键实现
c# 向驱动打印机发送命令打开钱箱
Copyright © 2011-2022 走看看