using System.Configuration;
using System.Windows.Forms; namespace Allyn.Common
{
public class XmlHeper
{
///<summary>
///返回Config文件中appSettings配置节的value项
///</summary>
///<param name="strKey">节点Key</param>
///<returns>值</returns>
public static string GetAppConfig(string strKey)
{
string file = Application.ExecutablePath;
Configuration config = ConfigurationManager.OpenExeConfiguration(file); foreach (string key in config.AppSettings.Settings.AllKeys)
{
if (key == strKey)
{
return config.AppSettings.Settings[strKey].Value.ToString();
}
}
return string.Empty;
} ///<summary>
///在Config文件中appSettings配置节增加一对键值对
///</summary>
///<param name="newKey">节点名称</param>
///<param name="newValue">信值</param>
public static void UpdateAppConfig(string newKey, string newValue)
{
string file = System.Windows.Forms.Application.ExecutablePath;
Configuration config = ConfigurationManager.OpenExeConfiguration(file); bool exist = false; foreach (string key in config.AppSettings.Settings.AllKeys)
{
if (key == newKey) { exist = true; }
} if (exist) { config.AppSettings.Settings.Remove(newKey); } config.AppSettings.Settings.Add(newKey, newValue);
config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings");
}
}
}

转载:https://www.cnblogs.com/allyn/p/10178067.html

转载:轻量级Config文件AppSettings节点编辑帮助类的更多相关文章

  1. 利用HttpWebRequest模拟表单提交 JQuery 的一个轻量级 Guid 字符串拓展插件. 轻量级Config文件AppSettings节点编辑帮助类

    利用HttpWebRequest模拟表单提交   1 using System; 2 using System.Collections.Specialized; 3 using System.IO; ...

  2. 轻量级Config文件AppSettings节点编辑帮助类

    using System.Configuration; using System.Windows.Forms; namespace Allyn.Common { public class XmlHep ...

  3. c# 根据配置文件路径,设置和获取config文件 appSettings 节点值

    /// <summary> /// 获取编译后的主配置文件节点值 /// </summary> /// <param name="key">&l ...

  4. 修改和获取web.config或app.config文件appSettings配置节中的Add里的value属性 函数

    1: /// <summary> 2: /// 修改web.config或app.config文件appSettings配置节中的Add里的value属性 3: /// </summ ...

  5. Machine.config 文件中节点<machineKey>的强随机生成

    Machine.config 文件中节点<machineKey>的强随机生成 <machineKey>这个节允许你设置用于加密数据和创建数字签名的服务器特定的密钥.ASP.NE ...

  6. C# 对 App.config的appSettings节点数据进行加密

    .NET平台下的Winform和Asp.net的配置文件默认都是明文保存的,本文使用的是.Net自身如何加密配置文件,不包含自定义的加密规则 但.Net是提供了直接对配置文件加密的功能的,使用.Net ...

  7. winform 项目获取app.config 中appSettings节点数据

    <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSe ...

  8. Web.config中appSettings节点值两种读取方法

        <appSettings>    <add key="ClientPort" value="5252"/>   <add ...

  9. 获取 config文件的节点值

    System.Configuration.ConfigurationManager.AppSettings["followTemplate"];

随机推荐

  1. sql语言 含有包含关系的查询 (含mysql 和sql sever)

    一.sql中查询包含关系的查询 sql语句中包含关系可以使用 in 和exist,但有些时候仅仅用这两个是不够的,还有表示方法是  not exist(b expect a )可以表示a包含b. 二. ...

  2. layui选项卡-内容为echarts图显示不全的问题

    var width = $("威胁类型ID").width();var height = $("威胁类型ID").height(); $("#威胁来源 ...

  3. vue day3 bootstrap 联动下拉

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta ht ...

  4. URI,url简介

    URI,URL是什么? URI :Uniform Resource Identifier,统一资源标识符: URL:Uniform Resource Locator,统一资源定位符: URN:Unif ...

  5. vc6.0使用

    1.文件结构 工作空间dsw 工程1    Source file        .cpp,main    Header file        .h    Resource files 工程2   ...

  6. 关于if...else语句的小注意

    if...else是一个使用非常频繁的条件语句,在条件满足时执行if下的代码,条件不满足时执行else下的代码.但在使用过程中会由于粗心犯一些错误. 比如我想要把性别的默认值设置为“男”,应该进行如下 ...

  7. python中的列表的嵌套与转换

    第一种方法:这行代码的for循环的意识,是先将matrix列表中的每行的第一个元素拿出. matrix =[[1,2,3,4],[5,6,7,8],[9,10,11,12]] transposed_r ...

  8. ajax 调用webservice 跨域问题

    注意两点 1. 在webservice的config中加入这段位置 (注意不是调用webservice的webconfig中加入) <system.webServer>     <! ...

  9. DevExpress中barManager下的toolbar如何在panel中显示

    如题,我的Dev Toolbar需要在一个pannel中显示,并且居于最顶部.可是好像默认情况下toolbar都是在窗体的最顶部的,如何设置才能使其位于一个panel的最顶部呢? 解决方案:经过测试, ...

  10. lvs基础及部署

    LVS简介   LVS--Linux Vritual Server 即linux虚拟服务器,1998年5月由章文嵩博士开发并开源,目前全球多个国家的企业单位都在使用LVS构建集群服务.   LVS可实 ...