轻量级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"];
随机推荐
- m序列生成电路
m序列
- JS Async Callback
AsyncCallback 意义: 异步操作完成时调用的方法 语法1: 构造异步回调对象 AsyncCallback 异步回调对象名asyncCallback = new AsyncCallback( ...
- 【C#】解析C#中JSON.NET的使用
目录结构: contents structure [-] JSON.NET简介 Serializing and Deserializing JSON Json Convert Json Seriali ...
- 【轻松前端之旅】<!DOCTYPE>标签
前端学习,先学习HTML,CSS,Javascript HTML - HyperText Markup Language HTML-超文本标记语言,提供了一种标记网页内容的方法. 浏览器怎么知道如何显 ...
- PHP可变函数
可变函数是指如果一个变量名后有圆括号,PHP将寻找与变量的值同名的函数,并尝试执行它 可变函数可以用来实现包括回调函数,函数表在内的用途 $str = 'strtolower'; echo $str( ...
- centos7 lvm实例
1.lvm安装 rpm -qa|grep lvm lvm version yum install -y lvm2* 2.磁盘分区 fdisk -l fdisk /dev/xvdb1 #分区结束标记 t ...
- oracle compile 编译无效对象
原博主:http://blog.csdn.net/tianlesoftware/article/details/4843600 Applies to: Oracle Server - Enterpri ...
- dj 中间件
中间件的概念 中间件顾名思义,是介于request与response处理之间的一道处理过程,相对比较轻量级,并且在全局上改变django的输入与输出.因为改变的是全局,所以需要谨慎实用,用不好会影响到 ...
- Andrew机器学习第一课
批梯度下降算法: 训练样本为一个时:更新Θi 让代价函数最小,利用沿梯度下降方向函数会变得越来越小.这个函数是代价函数J关于(Θi )的.这里并没有在讨论x,y. 关于为什么式子(图是复制的 ...
- 第09章:MongoDB-CRUD操作--文档--修改--update
①语法 db.collection.update( <query>, <update>, { upsert: <boolean>, multi: <boole ...