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;
}
查看全文
相关阅读:
吧
bzoj3052: [wc2013]糖果公园
莫队算法心得
bzoj1104: [POI2007]洪水pow
bzoj1102: [POI2007]山峰和山谷Grz
bzoj1121: [POI2008]激光发射器SZK
bzoj1113: [Poi2008]海报PLA
bzoj1103: [POI2007]大都市meg
bzoj1396: 识别子串
bzoj3756: Pty的字符串
原文地址:https://www.cnblogs.com/lidune/p/546752.html
最新文章
CLR via C#(07)-静态类,分部类
CLR via C#(06)- 构造器
0x06算法设计与分析复习(二):算法设计策略-贪心法1
0x05算法设计与分析复习(二):算法设计策略-分治法4
0x05算法设计与分析复习(二):算法设计策略-分治法3
0x05算法设计与分析复习(二):算法设计策略-分治法1
0x05算法设计与分析复习(二):算法设计策略-分治法2
0x01算法设计与分析复习(一):算法和算法分析
Beamer中数学符号字体
Win10快捷键
热门文章
Graphviz入门
(云主机&虚拟机)centos7安装nginx
Django系列(一)
字典
python函数系列之sorted()
JQuery之左侧菜单
Python函数系列之eval()
requests之json系列(一)
pandas之系列操作(一)
excel 中怎么让两列姓名相同排序(转)
Copyright © 2011-2022 走看看