/// <summary>
/// 更新设置
/// </summary>
/// <param name=”settingName“></param>
/// <param name=”valueName“></param>
public static void UpdateSettingString(string settingName, string valueName)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);if (ConfigurationManager.AppSettings[settingName] != null)
{
config.AppSettings.Settings.Remove(settingName);
}
config.AppSettings.Settings.Add(settingName, valueName);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(“appSettings“);
}
二、读取存入内容
/// 读取客户设置
/// </summary>
/// <param name=”settingName”></param>
/// <returns></returns>
public static string GetSettingString(string settingName)
{
try
{
string settingString = ConfigurationManager.AppSettings[settingName].ToString();
return settingString;
}
catch (Exception)
{
return null;
}
}
三、使用
UpdateSettingString("userName", LoginName);
LoginName = GetSettingString("userName");
四、完结。
原文地址:https://blog.csdn.net/a876106354/article/details/134692060
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_16139.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!