zoukankan      html  css  js  c++  java
  • 给Config的appSettings节点赋值

     /// <summary>
            /// 更新config的AppSettings配置值
            /// </summary>
            /// <param name="key"></param>
            /// <param name="newValue"></param>
            /// <returns></returns>
            private bool UpdateAppConfig(string key, string newValue)
            {
                bool isModified = false;
                foreach (string appkey in ConfigurationManager.AppSettings)
                {
                    if (key == appkey)
                    {
                        isModified = true;
                    }
                }       // Open App.Config of executable                
                // You need to remove the old settings object before you can replace it      
                if (isModified)
                {
                    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    config.AppSettings.Settings[key].Value = newValue;
                    config.Save(ConfigurationSaveMode.Modified);
                    ConfigurationManager.RefreshSection("appSettings");
                    return true;
                    //config.AppSettings.Settings.Remove(newKey);
                }
                else
                {
                    return false;
                }
            }
     /// <summary>
            /// 计算文件的hash值 
            /// </summary>
            public static string CalcFileHash(string FilePath)
            {
                MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
                byte[] hash;
                using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096))
                {
                    hash = md5.ComputeHash(fs);
                }
                return BitConverter.ToString(hash);
            }
  • 相关阅读:
    从jQuery看JavaScript匿名函数与闭包
    向properties文件中写入信息(针对获取properties文件失败的总结)
    windows系统下的redis启动教程
    第零次作业
    C语言博客作业02循环结构
    c语言博客作业03函数
    第一次作业
    笔记
    整型类型
    鸡和兔
  • 原文地址:https://www.cnblogs.com/ypyhy/p/6760965.html
Copyright © 2011-2022 走看看