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;
}
查看全文
相关阅读:
TransmitFile
xml
鼠标划过表格行变色-简洁实现
关于表变量
显式接口成员实现
华为致新员工书
C#实现的堆栈
Gridview中合并单元格,某字段的内容相同时如何只显示一个,屏蔽相同列或行的内容(转)
ASP.NET 验证控件
动态SQL EXEC
原文地址:https://www.cnblogs.com/lidune/p/546752.html
最新文章
C# this,base 关键字分析(转载)
C# 事件机制归纳(转载)
如何制作U盘系统盘以及U盘安装操作系统的方法
微软官方Windows 7 USB/DVD Download Tool下载
学习C# delegate和 event
Official Windows 7 SP1 ISO Image Downloads
解决Windows 7安装后出现隐藏分区问题
Process and Thread
C#调用bat批处理
Mina、Netty、Twisted一起学(五):整合protobuf
热门文章
Mina、Netty、Twisted一起学(四):定制自己的协议
Mina、Netty、Twisted一起学(一):实现简单的TCP服务器
Mina、Netty、Twisted一起学(六):session
Mina、Netty、Twisted一起学(三):TCP消息固定大小的前缀(Header)
Mina、Netty、Twisted一起学(二):TCP消息边界问题及按行分割消息
showPop
SQL Server 数据库使用备份还原造成的孤立用户和对象名‘xxx’无效的错误的解决办法(收藏)
How to send and receive image using socket programming in c#
IBatisNet 开发指南系列文章更新
删除Player上指定的媒体文件
Copyright © 2011-2022 走看看