zoukankan
html css js c++ java
读写配置文件
;读写配制文件操作
#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
;读写配制文件操作
查看全文
相关阅读:
JS打印代码示例
javascript图片360°旋转
动态载入/删除/更新外部 JavaScript/Css 文件
AviSynth入门与应用指南
汇编64讲(搞免杀、破解必看)在线观看
C#模拟登录总结
同时使用apache和IIS,共用80端口的一个解决方案
Dos命令集合
批处理for命令详解
JavaScript定义类的几种方式
原文地址:https://www.cnblogs.com/noahsky/p/1078536.html
最新文章
未能在指定文件夹中创建本地存储区,请选择其他位置。可以检查事件日志以了解详细信息
Visual c++ 2011419
CBrush,CFont,CPen
Visual C++ 2011417
Visual C++ 2011416
visual c++ for .net(新语法)
文件夹浏览(SHBrowseForFolder)
Visual C++ 基础数据类型的转换
Visual C++ 2011412
Win32窗体控件方法与消息
热门文章
Visual C++ 2011415
JavaScript分页打印代码
JavaScript操作Excel
C#中利用Process类调用外部程序以及执行Dos命令
汇编之WinASM/RadASM系列培训
符合w3c标准flash(swf)插入代码,常用flash参数设置
AviSynth 教程(收集、整理)
ffmpeg在windows下视频采集
JavaScript之appendChild、insertBefore和insertAfter
Javascript热键兼容ie,firefox
Copyright © 2011-2022 走看看