【发布时间】:2011-08-24 13:53:17
【问题描述】:
我在 App.config 文件中定义了一个自定义部分,并且该 customSection 的所有配置属性都已在 configSource 文件中指定的外部配置文件中定义。
现在的情况是,每当我运行程序时,我都会修改外部配置文件中存在的属性值,我需要一种方法将这些值保存在外部配置文件中。
如何保存这些值?使用常规方式写入文件是唯一的选择吗?
考虑以下关于我想在应用程序中做什么的场景:
App.config 文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="example" type="CustomConfig.ExampleSection,
CustomConfig" />
</configSections>
<example
configSource="example.config"
/>
<appSettings>
<add key="version_string" value="1.01" />
</appSettings>
</configuration>
example.config
<?xml version="1.0"?>
<example version="A sample string value."/>
假设在程序执行期间版本的值被更改为“Foo”。如何将该值永久保存在 example.config 文件中,以便当我退出应用程序并再次重新加载它时,版本的值将是 Foo。
【问题讨论】:
标签: c# .net app-config