public static void SetValue(string key, string value) { string file = System.Windows.Forms.Application.ExecutablePath; Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap { ExeConfigFilename = file + ".config" }, ConfigurationUserLevel.None); configuration.AppSettings.Settings[key].Value = value; configuration.Save(); }
配置文件刷新
ConfigurationManager.RefreshSection("appSettings");