当前位置: 代码迷 >> ASP.NET >> 为什么报错,未将对象引用设置到对象的实例,该如何处理
  详细解决方案

为什么报错,未将对象引用设置到对象的实例,该如何处理

热度:4626   发布时间:2013-02-25 00:00:00.0
为什么报错,未将对象引用设置到对象的实例

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

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中可能带\,你单步跟踪看看是不是这错了
  相关解决方案