我想读的app.config
值,显示它在消息框中,更改使用外部文本编辑器的价值,并最终显示更新的值。如何重新加载/刷新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>
这不是一个问题的答案,直到它解释了代码做什么,以及为什么它解决了他的问题。 – 2013-04-07 11:27:19