如何编程序实现修改web.config中<add key="pagesize" value="5">字段的值。

解决方案 »

  1.   

    XmlDocument webconfigDoc = new XmlDocument();
    string filePath = HttpContext.Current.Request.PhysicalApplicationPath + @"\web.config";                                                                
     string xPath = "/configuration/appSettings/add[@key='?']";
                webconfigDoc.Load(filePath);                   
                XmlNode passkey = webconfigDoc.SelectSingleNode(xPath.Replace("?","pwd"));
                passkey.Attributes["value"].InnerText ="";
                webconfigDoc.Save(filePath)