C#實現appSettings節點讀取與修改的方法

來源:互聯網
上載者:User

標籤:bool   .net自訂控制項   normal   date   網路爬蟲   str   color   動效   功能   

本文執行個體講述了C#實現appSettings節點讀取與修改的方法,分享給大家供大家參考。具體方法如下:

關鍵代碼如下:


代碼如下:

public static string GetAppSettingsValue(string key)

{

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#和Java中二維數組區別分析

C#實現appSettings節點讀取與修改的方法

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.