zoukankan      html  css  js  c++  java
  • c# 配置文件App.config操作类库

    public class ConfigOperator
        {
            #region 从配置文件获取Value
            /// <summary>
            /// 从配置文件获取Value
            /// </summary>
            /// <param name="key">配置文件中key字符串</param>
            /// <returns></returns>
            public static string GetValueFromConfig(string key)
            {
                try
                {
                    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    //获取AppSettings的节点 
                    AppSettingsSection appsection = (AppSettingsSection)config.GetSection("appSettings");
                    return appsection.Settings[key].Value;
                }
                catch
                {
                    return "";
                }
            }
            #endregion
    
            #region 设置配置文件
            /// <summary>
            /// 设置配置文件
            /// </summary>
            /// <param name="key">配置文件中key字符串</param>
            /// <param name="value">配置文件中value字符串</param>
            /// <returns></returns>
            public static bool SetValueFromConfig(string key, string value)
            {
                try
                {
                    //打开配置文件 
                    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    //获取AppSettings的节点 
                    AppSettingsSection appsection = (AppSettingsSection)config.GetSection("appSettings");
                    appsection.Settings[key].Value = value;
                    config.Save();
    
                    return true;
                }
                catch
                {
                    return false;
                }
            }
            #endregion
  • 相关阅读:
    移植spdylay到libcurl
    用到的C++标准库
    libcurl底层调用逻辑
    socket编程
    linux的一些机制Signal, Fork,
    openssl 编程
    对称加密,非对称加密
    ajax提交整个form表单
    一道基础的for语句js编译过程
    怎样将浏览器一句话变为文本编辑器
  • 原文地址:https://www.cnblogs.com/xuxiaoshuan/p/5884406.html
Copyright © 2011-2022 走看看