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. HTML的select控件美化

    HTML的select控件美化 CSS: .div-select { border: solid 1px #999; height: 40px; line-height: 40px; cursor: ...

  2. C#微信公众平台开发—高级群发接口

    涉及access_token的获取请参考<C#微信公众平台开发—access_token的获取存储与更新> 一.为了实现高级群发功能,需要解决的问题 1.通过微信接口上传图文消息素材时,J ...

  3. Model元数据提供机制小结

    在最开始先我得说说我看这部分的情况,最开始被各种ModelMetadata和各种ModelMetadataProvider给搞晕了,就几页书花了我好大的精力去看,直到后来看了一幅类图,细细看各个类之间 ...

  4. 【人在江湖飘,哪有不带刀】神器Jumony

    大神博客:http://www.cnblogs.com/Ivony/p/3447536.html 项目地址:https://github.com/Ivony/Jumony 1.安装Jumony包 在N ...

  5. 通过泛型数据,操作SQL数据库

    本人在操作数据库的时候,采用将对象的形式操作传入数据库,经过大量百度和朋友帮助,总结出如下两个接口.用于插入数据,提取数据. 要这样操作的前提条件,就是类名和表名一致,类字段和表字段一致就可以了 // ...

  6. 编译安装rabbitmq服务端

    有一种方式是:下载rabbitmq-server-generic-unix压缩包,是不用编译的.是已经编译好的源码了 下面介绍编译源码安装   总括: 需要以下步骤:   1.安装erlange.因为 ...

  7. CI框架源码阅读笔记3 全局函数Common.php

    从本篇开始,将深入CI框架的内部,一步步去探索这个框架的实现.结构和设计. Common.php文件定义了一系列的全局函数(一般来说,全局函数具有最高的加载优先权,因此大多数的框架中BootStrap ...

  8. 【java学习系列】 Android第一本书《第一行代码》

    开始Java的学习,从Android,开始吧.<第一代码>开始阅读和调试demo例子. 下面是 <第一行代码>的思维导图:

  9. Several ports (8080, 8009) required by Tomcat v6.0 Server at localhost are already in use.

    遇到这个问题似然重启是个办法,但是真心好累.. 1.在dos下,输入  netstat   -ano|findstr  8080 //说明:查看占用8080端口的进程 显示占用端口的进程 2.在任务管 ...

  10. Linux学习笔记16--Linux扩展权限

    默认权限: 每一个终端都有一个umask属性,用于确定新建文件.新文件夹的默认权限. umask使用数字权限方式表示,如:022   一般来说,普通用户的默认umask是002,root用户的默认um ...