public class AppSettingManager
{
public static bool Update(string key, string value)
{ try
{
var config = Create();
if (config == null)
{
return false;
}
var isModified = !string.IsNullOrEmpty(Get(key));
if (isModified)
{
config.AppSettings.Settings.Remove(key);
}
// Add an Application Setting.
config.AppSettings.Settings.Add(key, value);
// Save the changes in App.config file.
config.Save(ConfigurationSaveMode.Modified);
// Force a reload of a changed section.
ConfigurationManager.RefreshSection("appSettings");
return true;
}
catch (Exception)
{
return false;
} } public static bool Add(string key, string value)
{
try
{
var config = Create();
if (config == null)
{
return false;
}
config.AppSettings.Settings.Add(key, value);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
return true;
}
catch (Exception)
{
return false; } } public static string Get(string key)
{
var config = Create();
if (config == null)
{
return null;
}
return config.AppSettings.Settings[key].Value;
} private static Configuration Create()
{
try
{
return ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
}
catch (Exception)
{
return null;
}
}
}

AppSettingManager的更多相关文章

  1. 企业级工作流解决方案(十五)--集成Abp和ng-alain--Abp其他改造

    配置功能增强 Abp定义了各种配置接口,但是没有定义这些配置数据从哪里来,但是管理配置数据对于一个应用程序来说,是必不可少的一件事情. .net的配置数据管理,一般放在Web.config文件或者Ap ...

随机推荐

  1. JS 之DOM对象(2)

    http://www.cnblogs.com/zourong/p/4792394.html 这篇文件介绍了DOM1中的一些属性和方法,下面的内容主要介绍DOM2和DOM3中新增的内容. 框架的变化 框 ...

  2. 第三方框架 INTULocationManager 定位的一些方法

    gitub 下载 INTULocationManager #import "INTULocationManager.h" INTULocationManager *locMgr = ...

  3. 从0开始学Java——@override的作用

    早上跟着<jsp&Servlet学习笔记>来学习jsp,在使用eclipse创建了一个servlet类之后,发现自动创建的类和书上相比,doGet方法的前面少了@override, ...

  4. LeetCode:Path Sum I II

    LeetCode:Path Sum Given a binary tree and a sum, determine if the tree has a root-to-leaf path such ...

  5. 实践GDB

    调试工具简介:GDB  Unix程序员最常用的调试工具是GDB,这是由Richard Stallman(开源软件运动的领路人) 开发的GNU项目调试器,该工具在Linux开发中扮演了关键的角色. CG ...

  6. xcode 出现the file couldn't be opened 怎么解决

    右键——show In finder——显示xcode包内容——将有数字的删除——把有用的xcode双击

  7. Jenkins进阶系列之——06FTP publisher plugin插件下载(支持绝对路径)

    注意:绝对路径用/开头 绝对路径:/root/.jenkins/jobs/test/workspace/bbb/test.war 相对路径:bbb/test.war 点我下载

  8. [网站公告]23:00-05:00阿里云SLB升级会造成4-8次每次10秒的闪断

    大家好,阿里云将于今天夜里(7月29日23:00-7月30日05:00)对负载均衡服务(SLB)进行升级操作,升级期间我们使用的SLB实例会有4-8次的闪断,每次闪断时间10秒左右.闪断期间会造成网站 ...

  9. android之imgView插件的使用

    在开发中我们经常要用到图片下载功能,但我们可以在github上淘一些比较好的插件,这里介绍一款叫smartImageView的插件. 这里是其地址https://github.com/loopj/an ...

  10. 重构笔记---MEF框架(上)

    概述 这篇文章的目的是简要分析对比MAF和MEF,并详细举出MEF设计中的细节和扩展上的细节,达到让读者能实际操作的目的.其中,MAF的设计会附上我的代码,其实就是官方的代码我自己手动联系了一遍,但还 ...