会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
临渊羡鱼,不如退而结网
博客园
首页
新随笔
联系
订阅
管理
读写配置文件
;读写配制文件操作
#region
;读写配制文件操作
public
string
GetConfigString(
string
key)
{
return
ConfigurationManager.AppSettings[key];
}
//
没有加载时读取
public
string
GetConfigValue(
string
appKey)
{
XmlDocument xDoc
=
new
XmlDocument();
try
{
xDoc.Load(System.Windows.Forms.Application.ExecutablePath
+
"
.config
"
);
XmlNode xNode;
XmlElement xElem;
xNode
=
xDoc.SelectSingleNode(
"
//appSettings
"
);
xElem
=
(XmlElement)xNode.SelectSingleNode(
"
//add[@key='
"
+
appKey
+
"
']
"
);
if
(xElem
!=
null
)
return
xElem.GetAttribute(
"
value
"
);
else
return
""
;
}
catch
(Exception)
{
return
""
;
}
}
//
写操作
public
void
SetValue(
string
AppKey,
string
AppValue)
{
XmlDocument xDoc
=
new
XmlDocument();
//
获取可执行文件的路径和名称
xDoc.Load(System.Windows.Forms.Application.ExecutablePath
+
"
.config
"
);
XmlNode xNode;
XmlElement xElem1;
XmlElement xElem2;
xNode
=
xDoc.SelectSingleNode(
"
//appSettings
"
);
xElem1
=
(XmlElement)xNode.SelectSingleNode(
"
//add[@key='
"
+
AppKey
+
"
']
"
);
if
(xElem1
!=
null
) xElem1.SetAttribute(
"
value
"
, AppValue);
else
{
xElem2
=
xDoc.CreateElement(
"
add
"
);
xElem2.SetAttribute(
"
key
"
, AppKey);
xElem2.SetAttribute(
"
value
"
, AppValue);
xNode.AppendChild(xElem2);
}
xDoc.Save(System.Windows.Forms.Application.ExecutablePath
+
"
.config
"
);
}
#endregion
;读写配制文件操作
posted @
2008-02-23 10:47
noahsky
阅读(
165
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告