[.NET] : 自訂Configuration區段的資料寫入

來源:互聯網
上載者:User

 

前言 :

自訂Configuration區段的資料讀取,先前小朱有寫了一系列的文章。
本篇文章描述,如何使用程式碼做自訂Configuration的資料寫入。

 

注意 :

在 Microsoft Visual Studio IDE除錯環境下,執行程式寫入.config時。
程式寫入的將會是*.vshost.exe.config,而不是預期中的 *.exe.config。
並且程式執行結束之後,IDE會覆蓋*.vshost.exe.config成為寫入前的狀態。
因此會誤認為程式執行失敗。

 

只要編譯完畢之後,點選bin目錄底下的*.exe執行。
再去檢查*.exe.config,就可以看到預期中的結果。

 

相關資料 :

[ASP.NET]撰寫自己的 Configuration 區段 Part 1 : http://www.dotblogs.com.tw/regionbbs/archive/2009/05/08/custom_configuration_section_in_web_config.aspx
[ASP.NET]撰寫自己的 Configuration 區段 Part 2 : http://www.dotblogs.com.tw/regionbbs/archive/2009/09/17/orgainzeyoursectionintogroupforconfiguration.aspx
[ASP.NET]撰寫自己的 Configuration 區段 Part 3 : http://www.dotblogs.com.tw/regionbbs/archive/2009/10/09/customconfigurationelementcollection.aspx

 

範常式序 :

檔案下載 :CLK.ConfigurationSample.rar

 

自訂ConfigurationSection

 

設定.config

 

寫入程式

 

執行結果

 

後記 :

自訂Configuration區段,
如果都用System.Configuration命名空間裡的型別來做屬性,做讀取跟寫入其實蠻方便的。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.