日期:2014-05-18 浏览次数:21204 次
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="strValue"></param>
public void Modify(string key, string strValue) //两个参数:要修改的键值 和 要修改的新值;
{
string flagstr = strValue;
if (strValue == string.Empty)
{
MessageBox.Show("连接串不能为空!");
return;
}
//string XPath = "/configuration/userInfo/add[@key='?']";
try
{
string XPath = "/configuration/appSettings/add[@key='?']";
XmlDocument domWebConfig = new XmlDocument();
//domWebConfig.Load((HttpContext.Current.Server.MapPath("web.config")));
domWebConfig.Load(filepath);
XmlNode addKey = domWebConfig.SelectSingleNode((XPath.Replace("?", key)));
if (addKey == null)
{
//Response.Write("<script>alert (\"没有找到<add key='" + key + "' value=.../>的配置节\")</script>");
MessageBox.Show("没有找到<add key='" + key + "'>的配置节");
return;
}
addKey.Attributes["value"].InnerText = strValue;
domWebConfig.Save(filepath);
MessageBox.Show("数据库连接配置成功","信息提示");
}
catch
{
}
}