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);
            }
  • 相关阅读:
    PHP开发APP接口(三)
    PHP开发APP接口(二)
    PHP开发APP接口(一)
    解密PHP模糊查询技术
    流程的问题
    德邦项目《表》
    微信公众号开发1
    在world2013中插入GB_2312
    HTML5笔记(一)
    蓝色文字显示
  • 原文地址:https://www.cnblogs.com/ypyhy/p/6760965.html
Copyright © 2011-2022 走看看