轻量级Config文件AppSettings节点编辑帮助类
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");
}
}
}
轻量级Config文件AppSettings节点编辑帮助类的更多相关文章
- 利用HttpWebRequest模拟表单提交 JQuery 的一个轻量级 Guid 字符串拓展插件. 轻量级Config文件AppSettings节点编辑帮助类
利用HttpWebRequest模拟表单提交 1 using System; 2 using System.Collections.Specialized; 3 using System.IO; ...
- 转载:轻量级Config文件AppSettings节点编辑帮助类
using System.Configuration; using System.Windows.Forms; namespace Allyn.Common { public class XmlHep ...
- c# 根据配置文件路径,设置和获取config文件 appSettings 节点值
/// <summary> /// 获取编译后的主配置文件节点值 /// </summary> /// <param name="key">&l ...
- Machine.config 文件中节点<machineKey>的强随机生成
Machine.config 文件中节点<machineKey>的强随机生成 <machineKey>这个节允许你设置用于加密数据和创建数字签名的服务器特定的密钥.ASP.NE ...
- 修改和获取web.config或app.config文件appSettings配置节中的Add里的value属性 函数
1: /// <summary> 2: /// 修改web.config或app.config文件appSettings配置节中的Add里的value属性 3: /// </summ ...
- C# 对 App.config的appSettings节点数据进行加密
.NET平台下的Winform和Asp.net的配置文件默认都是明文保存的,本文使用的是.Net自身如何加密配置文件,不包含自定义的加密规则 但.Net是提供了直接对配置文件加密的功能的,使用.Net ...
- Web.config中appSettings节点值两种读取方法
<appSettings> <add key="ClientPort" value="5252"/> <add ...
- winform 项目获取app.config 中appSettings节点数据
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSe ...
- 获取 config文件的节点值
System.Configuration.ConfigurationManager.AppSettings["followTemplate"];
随机推荐
- Two Sum II - Input array is sorted LT167
Given an array of integers that is already sorted in ascending order, find two numbers such that the ...
- 安装ubuntu16.04的时候出现的detecting file system
解决问题方法是,进入主界面执行,如下操作即可: sudo umount -l /isodevice
- HYSBZ - 3676
模板题.问你一个串里最大的值(回文子串*出现次数) /* gyt Live up to every day */ #include<cstdio> #include<cmath> ...
- ssh 常用命令
1.复制SSH密钥到目标主机,开启无密码SSH登录 ssh-copy-id user@host 如果还没有密钥,请使用ssh-keygen命令生成. 2.从某主机的80端口开启到本地主机2001端口的 ...
- fiddler抓包时显示Tunnel to......443是怎么回事
之前公司的app使用的http协议,因此不需要安装证书也能够转包. 后来改成https协议后,在使用fiddler进行抓包时,一直出现tunnel to 443. 百度了好久也没有具体的解决办法,后来 ...
- 2018.11.24 poj2774Long Long Message(后缀数组)
传送门 实际上可以用后缀自动机秒掉 当然后缀数组也挺好写. 我们将两个字符串接在一起,为了方便中间用一个特殊字符连接. 然后对新字符串求heightheightheight数组. 求出来之后对所有满足 ...
- $.cookie is not a function的错误原因
网上说的原因是:“手残导入2次jquery库文件 ” 是的,就是这个原因.引入了两次jquery.js
- PARSEC安环境配置、运行
1.getting started 2.run PARSEC on simulators Full-System Simulators: such as Simics, GEM5.Trace-Driv ...
- python的6种基本数据类型--字典
python的6种基本数据类型--字典 字典 字典的定义与特性 字典是Python语言中唯一的映射类型. 定义:{key1:value1,key2:value2} 1.键与值用冒号":& ...
- excel的小bug
http://muchong.com/html/201710/3913047.html Excel也有相同现象,试着计算:exp(-1.5^2),exp(0-1.5^2),exp(-(1.5)^2)看 ...