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);
            }
  • 相关阅读:
    因特网中和多媒体有关的协议
    进程与线程
    线程模型
    SMP PVP Cluster
    读写者
    回调函数
    环境变量
    堆与栈的区别
    操作系统中的同步、异步、阻塞和非阻塞
    Razor潜入2令人疑惑的LocateOwner方法
  • 原文地址:https://www.cnblogs.com/ypyhy/p/6760965.html
Copyright © 2011-2022 走看看