[.NET] : 自定义Configuration区段的资料写入

前言 :

自定义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
image

设定.config
image

写入程序
image

执行结果
image

后记 :

自定义Configuration区段,
如果都用System.Configuration命名空间里的型别来做属性,做读取跟写入其实蛮方便的。

原文地址:https://www.cnblogs.com/clark159/p/2205122.html