日期:2014-05-18  浏览次数:20346 次

为什么报错,未将对象引用设置到对象的实例

代码如下,请大家帮忙看看为什么报这样的错误

XmlDocument   webconfigDoc   =   new   XmlDocument();  
string   filePath   =   HttpContext.Current.Request.PhysicalApplicationPath   +   @ "\web.config ";  
        webconfigDoc.Load(filePath);  
XmlElement   newElement   =   webconfigDoc.DocumentElement;
        XmlNodeList   elemList   =   newElement.GetElementsByTagName( "user ");
elemList[1].InnerText   =   "iieeie ";
        webconfigDoc.Save(filePath);

------解决方案--------------------
filePath是否正确
string filePath = HttpContext.Current.Request.PhysicalApplicationPath + @ "\web.config ";
去掉@ "\web.config ";中的\,因为PhysicalApplicationPath中可能带\,你单步跟踪看看是不是这错了