Winform读写App.config文件以及重启程序
2014-03-27 10:18
507 查看
//重启主程序 //System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location); #region 读存app.config字段值 public static string GetConfigValue(string appKey) { XmlDocument xDoc = new XmlDocument(); try { //缓存路径 xDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config"); System.Xml.XmlNode xNode; System.Xml.XmlElement xElem; xNode = xDoc.SelectSingleNode("//appSettings"); xElem = (System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='" + appKey + "']"); if (xElem != null) return xElem.GetAttribute("value"); else return ""; } catch { return ""; } } public static void SetConfigValue(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
相关文章推荐
- Winform读写App.config文件以及重启程序
- Winform读写App.config文件以及重启程序
- Winform读写App.config文件以及重启程序
- winform客户端程序实时读写app.config文件
- c#,WinForm中读写配置文件App.config
- C# WinForm程序的App.Config数据库连接配置文件
- winform程序读取和改写配置文件App.config元素的值
- winform程序读取和改写配置文件App.config元素的值
- winform程序读取和改写配置文件App.config元素的值
- winform程序读取和改写配置文件App.config元素的值
- winform程序读取和改写配置文件App.config元素的值
- winform程序读取和改写配置文件App.config元素的值
- c#,WinForm中读写配置文件App.config
- c#Winform程序调用app.config文件配置数据库连接字符串
- c#Winform程序调用app.config文件配置数据库连接字符串 SQL Server文章目录 浅谈SQL Server中统计对于查询的影响 有关索引的DMV SQL Server中的执行引擎入门 【译】表变量和临时表的比较 对于表列数据类型选择的一点思考 SQL Server复制入门(一)----复制简介 操作系统中的进程与线程
- winform程序读取和改写配置文件App.config元素的值
- C# WinForm程序App.Config数据库连接配置文件的使用过程
- winform程序读取和改写配置文件App.config元素的值
- c#winform 程序 App.config文件加密
- winform程序读取和改写配置文件App.config元素的值