编写自定义的部分到的app.config [英] Writing custom sections into app.config

查看:140
本文介绍了编写自定义的部分到的app.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要保存一些自定义的数据到应用程序配置文件,我需要在app.config中创建一些自定义的部分。从app.config中读取自定义数据是简单的任务,但我无法从我的PROGRAMM到app.config中写入信息。 为了找到这个问题的解决方案,我创建测试项目。

I want to save some custom data into application configuration file and I need to create some custom sections in app.config. Reading custom data from app.config is simple task, but I can't write information from my programm into app.config. For finding solution of this problem I create test project.

有关自定义栏目app.config中读取数据我用的信息从这篇文章:

For reading data from custom section app.config I used information from this article:

<一个href="http://devlicio.us/blogs/derik_whittaker/archive/2006/11/13/app-config-and-custom-configuration-sections.aspx">http://devlicio.us/blogs/derik_whittaker/archive/2006/11/13/app-config-and-custom-configuration-sections.aspx

推荐答案

第一个覆盖 IsReadyOnly() CustomConfigSection 返回false。

First override IsReadyOnly() in your CustomConfigSection to return false.

一旦你这样做,你应该能够做这样的事(这是ASP.NET,但也可能是transferably):

Once you've done that you should be able to do something like this (this is for ASP.NET, but it might be transferably):

System.Configuration.Configuration configFile = WebConfigurationManager.OpenWebConfiguration("~");
CustomConfigSection config = (CustomConfigSection)configFile.GetSection("Custom");
config.Tweak = 1;
config.Change = "foo";
configFile.Save();

给一个尝试。

Give that a try.

这篇关于编写自定义的部分到的app.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆