1。修改之后,手工刷新一下
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings[key].Value = value;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(“appSettings”);
2。通过操作xml方法
/// <summary>
/// Read confing
/// </summary>
/// <param name="path"></param>
/// <param name="appKey"></param>
/// <returns></returns>
public string GetConfigValue(string path,string appKey)
{
XmlDocument xDoc = new XmlDocument();
try
{
xDoc.Load(path);
//xDoc.Load(System.Windows.Forms.Application.ExecutablePath+".config");
XmlNode xNode;
XmlElement xElem;
xNode = xDoc.SelectSingleNode("//appSettings");
xElem = (XmlElement)xNode.SelectSingleNode("//add[@key='"+appKey+"']");
if(xElem!=null)
return xElem.GetAttribute("value");
else
return "";
}
catch(Exception)
{
return "";
}
}
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings[key].Value = value;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(“appSettings”);
2。通过操作xml方法
/// <summary>
/// Read confing
/// </summary>
/// <param name="path"></param>
/// <param name="appKey"></param>
/// <returns></returns>
public string GetConfigValue(string path,string appKey)
{
XmlDocument xDoc = new XmlDocument();
try
{
xDoc.Load(path);
//xDoc.Load(System.Windows.Forms.Application.ExecutablePath+".config");
XmlNode xNode;
XmlElement xElem;
xNode = xDoc.SelectSingleNode("//appSettings");
xElem = (XmlElement)xNode.SelectSingleNode("//add[@key='"+appKey+"']");
if(xElem!=null)
return xElem.GetAttribute("value");
else
return "";
}
catch(Exception)
{
return "";
}
}