/// <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); }