1. //重启主程序
    2. //System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
    3. #region 读存app.config字段值
    4. public static string GetConfigValue(string appKey)
    5. {
    6. XmlDocument xDoc = new XmlDocument();
    7. try
    8. {
    9. //缓存路径
    10. xDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config");
    11. System.Xml.XmlNode xNode;
    12. System.Xml.XmlElement xElem;
    13. xNode = xDoc.SelectSingleNode("//appSettings");
    14. xElem = (System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='" + appKey + "']");
    15. if (xElem != null)
    16. return xElem.GetAttribute("value");
    17. else
    18. return "";
    19. }
    20. catch
    21. {
    22. return "";
    23. }
    24. }
    25. public static void SetConfigValue(string AppKey, string AppValue)
    26. {
    27. XmlDocument xDoc = new XmlDocument();
    28. xDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config");
    29. XmlNode xNode;
    30. XmlElement xElem1;
    31. XmlElement xElem2;
    32. xNode = xDoc.SelectSingleNode("//appSettings");
    33. xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
    34. if (xElem1 != null) xElem1.SetAttribute("value", AppValue);
    35. else
    36. {
    37. xElem2 = xDoc.CreateElement("add");
    38. xElem2.SetAttribute("key", AppKey);
    39. xElem2.SetAttribute("value", AppValue);
    40. xNode.AppendChild(xElem2);
    41. }
    42. xDoc.Save(System.Windows.Forms.Application.ExecutablePath + ".config");
    43. }
    44. #endregion
        //重启主程序
//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文件以及重启程序的更多相关文章

  1. WinForm读写App.config配置文件

    一.配置文件概述: 应用程序配置文件是标准的 XML 文件,XML 标记和属性是区分大小写的.它是可以按需要更改的,开发人员可以使用配置文件来更改设置,而不必重编译应用程序.配置文件的根节点是conf ...

  2. 【C#】【WPF】如何读写app.config文件

    WPF生成的项目中会有.exe.config.一般是系统默认配置的 格式是xml格式,C#的项目可以直接读写这些文件.方法代码如下. public static string GetConnectio ...

  3. Winform 数据库连接app.config文件配置 数据库连接字符串

    1.添加配置文件 新建一个winform应用程序,类似webfrom下有个web.config,winform下也有个App.config;不过 App.config不是自动生成的需要手动添加,鼠标右 ...

  4. Winform数据库连接app.config文件配置

    1.添加配置文件 新建一个winform应用程序,类似webfrom下有个web.config,winform下也有个App.config;不过 App.config不是自动生成的需要手动添加,鼠标右 ...

  5. 关于读写APP.config文件能读却写不了的问题

    今天要求用winform写一个窗口用来读写一个App.config,要对  <appSettings>里面的add key和value进行添加和修改.要实现的效果图如下: -------- ...

  6. C#简单操作app.config文件

    即将操作的app.config文件内容如下 <?xml version="1.0" encoding="utf-8"?> <configura ...

  7. c#Winform程序调用app.config文件配置数据库连接字符串 SQL Server文章目录 浅谈SQL Server中统计对于查询的影响 有关索引的DMV SQL Server中的执行引擎入门 【译】表变量和临时表的比较 对于表列数据类型选择的一点思考 SQL Server复制入门(一)----复制简介 操作系统中的进程与线程

    c#Winform程序调用app.config文件配置数据库连接字符串 你新建winform项目的时候,会有一个app.config的配置文件,写在里面的<connectionStrings n ...

  8. WPF程序中App.Config文件的读与写

    WPF程序中的App.Config文件是我们应用程序中经常使用的一种配置文件,System.Configuration.dll文件中提供了大量的读写的配置,所以它是一种高效的程序配置方式,那么今天我就 ...

  9. C# 读写App.config配置文件的方法

    我们经常会希望在程序中写入一些配置信息,例如版本号,以及数据库的连接字符串等.你可能知道在WinForm应用程序中可以利用Properties.Settings来进行类似的工作,但这些其实都利用了Ap ...

随机推荐

  1. PHP 判断是否为 AJAX 请求

    先说前端使用 jQuery 时怎么区分: jQuery 发出 ajax 请求时,会在请求头部添加一个名为 X-Requested-With 的信息,信息内容为:XMLHttpRequest 在后端可以 ...

  2. Android短信Notification的几个ID

    private static final int NOTIFICATION_ID = 123; public static final int MESSAGE_FAILED_NOTIFICATION_ ...

  3. 如何改变 FMX ListView 颜色

    需求:改变 ListView 颜色 适用:Firemonkey 任何平台 操作:Style 是改变控件外观最便捷的途径,ListView 也不例外,下面示范使用 StyleBook 来设定 ListV ...

  4. Java中用户界面布局

    绝对布局Absolute 通过放大或缩小界面的时候,组件大小和位置不会发生变化 浮动布局FlowLayout 调整应用程序窗口的大小时,组件将立刻重新排列 边界布局Border Layout 该位置有 ...

  5. idea配置maven并添加镜像配置

    1.打开maven存放文件夹找到 conf ->settings.xml 找到<mirrors>节点把下面内容写入节点内 配置为阿里云的镜像 <mirror> <i ...

  6. apache配置运行zendframework 2

    其实ZF不用安装,只需引入就行,将ZF的library引入到项目的vendor\ZF2  就可以在ZF中开发了 在php版本5.4以上, 1 确保开启 extension=php_pdo.dllext ...

  7. Python自动化测试工具Splinter简介和使用实例

    Splinter 快速介绍 官方网站:http://splinter.cobrateam.info/ 官方介绍: Splinter is an open source tool for testing ...

  8. mysql出错:Access denied for user 'root'@'localhost' (using password: YES)

    网站链接mysql数据库的时候,连接不上,并报出错误:Access denied for user 'root'@'localhost' (using password:YES) 这是个相当恼火的问题 ...

  9. Node.js Web 开发框架大全《中间件篇》

    这篇文章与大家分享优秀的 Node.js 中间件模块.Node 是一个服务器端 JavaScript 解释器,它将改变服务器应该如何工作的概念.它的目标是帮助程序员构建高度可伸缩的应用程序,编写能够处 ...

  10. 安卓 9.png 图片的制作

    安卓的九宫格png图片可以自定义拉伸的区域,所以可以很方便的适应不同宽度高度的设备. 9.png格式是很纯正的png格式,与普通的png不同的是9.png格式的图片最外围有一圈1像素的透明区域,或者说 ...