读取
this
.label3.Text
=
System.Configuration.ConfigurationSettings.AppSettings[
"
readPath
"
];
写,这种方法虽然能立刻修改配置文件,但好像要重启应用程序才能读取到修改后的结果。
//
修改App.config文件节点值
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(System.Windows.Forms.Application.ExecutablePath + " .config " );
XmlNode node = xmlDoc.SelectSingleNode( " //appSettings " );
XmlElement element = (XmlElement)node.SelectSingleNode( " //add [@key="readPath"] " );
if (element != null )
... {
element.SetAttribute("value", this.textBox3.Text.ToString());
}
xmlDoc.Save(System.Windows.Forms.Application.ExecutablePath + " .config " );
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(System.Windows.Forms.Application.ExecutablePath + " .config " );
XmlNode node = xmlDoc.SelectSingleNode( " //appSettings " );
XmlElement element = (XmlElement)node.SelectSingleNode( " //add [@key="readPath"] " );
if (element != null )
... {
element.SetAttribute("value", this.textBox3.Text.ToString());
}
xmlDoc.Save(System.Windows.Forms.Application.ExecutablePath + " .config " );