C#實現appSettings節點讀取與修改的方法
阿新 • • 發佈:2017-11-29
ffffff share 讀取 stat med modified 2-0 class exceptio
{
ConfigurationManager.RefreshSection(“appSettings”);
return ConfigurationManager.AppSettings[key] ?? string.Empty;
}
public static bool UpdateAppSettings(string key, string value)
{
var _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (!_config.HasFile)
{
throw new ArgumentException(“程序配置文件缺失!”);
}
KeyValueConfigurationElement _key = _config.AppSettings.Settings[key];
if (_key == null)
_config.AppSettings.Settings.Add(key, value);
else
_config.AppSettings.Settings[key].Value = value;
_config.Save(ConfigurationSaveMode.Modified);
return true;
}
C#實現appSettings節點讀取與修改的方法
本文地址: http://www.paobuke.com/develop/c-develop/pbk23438.html
.net 隨機生成漢字C#中委托用法實例分析C#從文件或標準輸入設備讀取指定行的方法 C#和Java中二維數組區別分析
本文實例講述了C#實現appSettings節點讀取與修改的方法,分享給大家供大家參考。具體方法如下:
關鍵代碼如下:
代碼如下:
{
ConfigurationManager.RefreshSection(“appSettings”);
return ConfigurationManager.AppSettings[key] ?? string.Empty;
}
public static bool UpdateAppSettings(string key, string value)
{
var _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (!_config.HasFile)
{
throw new ArgumentException(“程序配置文件缺失!”);
}
KeyValueConfigurationElement _key = _config.AppSettings.Settings[key];
if (_key == null)
_config.AppSettings.Settings.Add(key, value);
else
_config.AppSettings.Settings[key].Value = value;
_config.Save(ConfigurationSaveMode.Modified);
return true;
}
希望本文所述對大家的C#程序設計有所幫助。
除聲明外,跑步客文章均為原創,轉載請以鏈接形式標明本文地址C#實現appSettings節點讀取與修改的方法
本文地址: http://www.paobuke.com/develop/c-develop/pbk23438.html
相關內容
C#設計模式之Template模板方法模式實現ASP.NET自定義控件 密碼強度檢測功能DevExpress GridView自動滾動效果C#網絡爬蟲代碼分享 C#簡單的爬取工具解析C#設計模式編程中適配器模式的實現.net 隨機生成漢字C#中委托用法實例分析C#從文件或標準輸入設備讀取指定行的方法
C#實現appSettings節點讀取與修改的方法