winform中app.config的动态读写操作
来源:互联网 发布:德章泰穆雷体测数据 编辑:程序博客网 时间:2024/06/04 17:55
在winform中使用程序动态读取和修改App.config里面的appSettings当中的Value值,解决winform中没有的修改和修改后不能及时取得其值的问题:
//写操作
public static 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");
}
//读操作
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 "";
}
}
- winform中app.config的动态读写操作
- winform中读写App.config文件
- c#,WinForm中读写配置文件App.config
- winform 程序中读写app.config
- winForm安装过程中读写app.config
- C#中动态读写App.config配置文件
- c# winform app.config xml 配置文件 读写操作
- C#WinForm APP.CONFIG配置文件的操作
- WPF中读写app.config操作
- Winform中C#实现读写app.config中的connectionStrings
- winform的app.config
- winform app.config 操作类
- 如何动态修改winform的app.config的键值
- 动态修改winform的app.config的键值
- winform开发中对App.Config的写和读操作
- C#中动态读写App.config配置文件 - zyloveyrf jinghuazhi.com
- C#Winform动态读取App.Config文件
- C# 的winform中使用数据库连接字符串 -- app.config
- c#格式化数据输出
- Orient DB 0.9.6 Beta 发布-下载
- IE6下DIV错位
- ubuntu 9.10 root登录 vi支持backspace与方向键 SSH安装 退出xwindow快捷键设置 apt-get源获取 配置雅黑字体 小企鹅输入法安装 NetBeans字体乱码 编译环境 JDK安装
- XtraGrid同一列中值相同的单元格合并
- winform中app.config的动态读写操作
- ZFS 故障检修指南(一)
- Linux系统内核文件Cache管理机制简介
- 仅用U盘就可以去除win XP管理员密码
- 在Struts 2中使用JSON Ajax支持
- COLUMN-TOTAL/ROW-TOTAL关键词:
- hello
- 在系统菜单中添加显示和隐藏标题栏的方法!
- sql server2005安全管理之用户、角色、架构 与 权限