[配置文件] C#修改App.config,Web.config文件帮助类,ConfigHelper (转载)

时间:2023-03-09 08:10:17
[配置文件] C#修改App.config,Web.config文件帮助类,ConfigHelper (转载)

点击下载 ConfigHelper-sufei.rar

主要功能如下

.根据Key取Value值
.根据Key修改Value
.添加新的Key ,Value键值对
.根据Key删除项
/// <summary>
/// 编 码 人:苏飞
/// 联系方式:361983679
/// 更新网站:[url=http://www.sufeinet.com/thread-655-1-1.html]http://www.sufeinet.com/thread-655-1-1.html[/url]
/// </summary>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration; namespace AutoApk.FunctionClass
{
public class ConfigHelper
{
/// <summary>
/// 根据Key取Value值
/// </summary>
/// <param name="key"></param>
public static string GetValue(string key)
{
return ConfigurationManager.AppSettings[key].ToString().Trim();
} /// <summary>
/// 根据Key修改Value
/// </summary>
/// <param name="key">要修改的Key</param>
/// <param name="value">要修改为的值</param>
public static void SetValue(string key, string value)
{
ConfigurationManager.AppSettings.Set(key, value);
} /// <summary>
/// 添加新的Key ,Value键值对
/// </summary>
/// <param name="key">Key</param>
/// <param name="value">Value</param>
public static void Add(string key, string value)
{
ConfigurationManager.AppSettings.Add(key, value);
} /// <summary>
/// 根据Key删除项
/// </summary>
/// <param name="key">Key</param>
public static void Remove(string key)
{
ConfigurationManager.AppSettings.Remove(key);
}
}
}