XmlDocument doc = new XmlDocument();
            //doc.Load(Microsoft.SqlServer.Server.MapPath("Reres.xml"));            doc.Load(HttpContext.Current.Server.MapPath("~/Reres.xml"));            XmlNodeList nodes1 = doc.GetElementsByTagName("Table");
            foreach (XmlNode node1 in nodes1)    //第一层
            {
                if (node1.Attributes["Name"].Value == "User_Info")
                {
                    XmlNodeList nodes2 = node1.ChildNodes;
                    foreach (XmlNode node2 in nodes2)//第二层nodes1
                    {
                        if (node2.Attributes["Name"].Value == "User_ID")
                        {
                            textBox1.Text += node2["Chinese"].InnerText;
                            textBox2.Text += node2["English"].InnerText;
                            textBox3.Text += node2["Type"].InnerText;
                        }
                    }
                }
            }
doc.Load(HttpContext.Current.Server.MapPath("~/Reres.xml"));这句提示未将对象引用设置到对象的实例,求教各位指导啊

解决方案 »

  1.   

    路径不对,xmldoc.LoadXml(HttpContext.Current.Server.MapPath("~/Reres.xml"));http://blog.csdn.net/ff_1211/article/details/6022012
      

  2.   

    提示已经非常明确了:HttpContext.Current.Server其中至少有个成员是null,你断点调试,看看这个值!
      

  3.   

    路径不对,xmldoc.LoadXml(HttpContext.Current.Server.MapPath("~/Reres.xml"));
      

  4.   

    应该是 HttpContext对象为null
      

  5.   

    难道你实在winform中使用?winform中没有HttpContext.Current.Server这些对象的
      

  6.   

    不是路径问题应该是HttpContext.Current.Server中有null值了,设置个断点看看就可以了。
      

  7.   

    多谢各位啊!!!!
    6楼 net_lover,我是在winform中使用的,那该怎么解决这个问题呢?
      

  8.   

    doc.Load(Microsoft.SqlServer.Server.MapPath("Reres.xml"));这样又提示命名空间"Microsoft.SqlServer.Server"中不存在类型或命名空间名称,请教怎么解决
      

  9.   

    Winform直接doc.Load(@"d:\xxx\Reres.xml");或者doc.Load("Reres.xml"); 
    exe文件和xml在同一路径下或者doc.Load(Application.ExecutablePath + "\\Reres.xml"); 
      

  10.   

    路径问题吧
    c# winform用
    1:“Application.StartupPath”:获取当前应用程序所在目录的路径,最后不包含“\”;
    2:“Application.ExecutablePath ”:获取当前应用程序文件的路径,包含文件的名称;
    3:“AppDomain.CurrentDomain.BaseDirectory”:获取当前应用程序所在目录的路径,最后包含“\”;
    4:“System.Threading.Thread.GetDomain().BaseDirectory”:获取当前应用程序所在目录的路径,最后包含“\”;
    5:“Environment.CurrentDirectory”:获取当前应用程序的路径,最后不包含“\”;
    6:“System.IO.Directory.GetCurrentDirectory”:获取当前应用程序的路径,最后不包含“\”;