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. 关于ajax跨域的一些解决方案

    1.JSONP方式解决跨域问题 jsonp解决跨域问题是一个比较古老的方案(实际中不推荐使用),当然,在实际项目中如果要使用JSONP,一般会使用JQ等对JSONP进行了封装的类库来进行ajax请求 ...

  2. imp导入时 出现IMP-00017:由于 ORACLE 错误 6550, 以下语句失败: 解决方法

    cmd命令下--执行imp命令时,出现IMP-00017:由于 ORACLE 错误 6550, 以下语句失败: 解决办法:在imp命令里加入 statistics=none (不导入数据库统计信息) ...

  3. Google - Find Most People in Chat Log

    1. 给你一个chatting log file,format大概是这样的: A: bla B: bla bla C: bla bla bla 要你找出说话最多(看word number) 的K个人 ...

  4. JS效果

    多标签页效果 tab切换 <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset ...

  5. java中的可释放资源定义,类似c#中的using

    public static class FileDuplicator implements AutoCloseable { Scanner in = null; PrintWriter out = n ...

  6. spring aop无法拦截类内部的方法调用

    1.概念 拦截器的实现原理就是动态代理,实现AOP机制.Spring 的代理实现有两种:一是基于 JDK Dynamic Proxy 技术而实现的:二是基于 CGLIB 技术而实现的.如果目标对象实现 ...

  7. win10+vs2015编译caffe的cpu debug版本、部署matcaffe

    一.编译caffe 1.安装python-3.5.2-amd64.exe https://www.python.org/ftp/python/3.5.2/python-3.5.2-amd64.exe ...

  8. scoping作用域,anonymous function匿名函数,built-in functions内置函数

    作用域练习1 def test1(): print('in the test1') def test(): print('in the test') return test1 res = test() ...

  9. Browser Render Engine & Javascript Engine

    Browser Render Engine Programming Language Open Source Javascript Engine Comparation for CSS Compati ...

  10. pj2--图书管理系统

    这一次做得是图书管理系统. 下面是功能框图 下面是流程图 实际在做这个项目的时候根据相应的实际情况对功能流程等等做了一些小小的改变. 下面是一些值得记一笔的地方. 1.借用系统自带的导航控件(Bind ...