【发布时间】:2013-03-29 11:46:54
【问题描述】:
我想读取app.config 的值,将其显示在消息框中,使用外部文本编辑器更改值,最后显示更新后的值。
我尝试使用以下代码:
private void button2_Click(object sender, EventArgs e)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationManager.RefreshSection("appSettings");
ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name);
MessageBox.Show(ConfigurationManager.AppSettings["TheValue"]);
}
但它不起作用。它显示旧值(在外部文本编辑器中更改之前)。 有什么建议吗?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="TheValue" value="abc"/>
</appSettings>
</configuration>
【问题讨论】:
标签: c# .net app-config config