antdui-demo/Utils/AppSetting.cs
2024-08-20 13:31:18 +08:00

36 lines
1003 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntdUIDemo.Utils
{
public static class AppSetting
{
public static void UpdateAppSetting(string key, string value)
{
// 获取当前配置文件
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// 检查key是否存在存在则更新不存在则添加
if (config.AppSettings.Settings[key] != null)
{
config.AppSettings.Settings[key].Value = value;
}
else
{
config.AppSettings.Settings.Add(key, value);
}
// 保存更改
config.Save(ConfigurationSaveMode.Modified);
// 刷新配置节,确保更新被应用
ConfigurationManager.RefreshSection("appSettings");
}
}
}