我想读取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>