private void BtnReadWeb_Click(object sender, EventArgs e)
        {
            string  webPath = System.Web.HttpContext.Current.Server.MapPath("") + @"\Web.config";
            System.Console.ReadLine();
        }
总是出现:未将对象引用设置到对象的实例
谢谢各位兄长,怎么解决!

解决方案 »

  1.   

    你的Web.config存在在web根目录。
    你的当前页面也许不在web根目录
      

  2.   

    System.Console.ReadLine(); 
    ?????????????????
      

  3.   

    同上
    console是控制台命令吧!
    如果想在界面上显示,可以用:
    Messagebox.show(webpath);
      

  4.   

    是这句异常:string  webPath = System.Web.HttpContext.Current.Server.MapPath("") + @"\Web.config"; 楼上说过的方法,我都试过了,不行,请帮忙解决,多谢!
      

  5.   

    就是说string  webPath没有读到System.Web.HttpContext.Current.Server.MapPath("") + @"\Web.config"所产生的数据。
    你在这句设个断点,逐步调试一下,看走到这步的时候string  webPath的值是什麽,再检查一下等号后面是否写正确
      

  6.   

    1、Server.MapPath("/")
    注:获得应用程序根目录所在的位置,如 C:\Inetpub\wwwroot\。
    2、Server.MapPath("./")
    注:获得所在页面的当前目录,等价于Server.MapPath("")。
    3、Server.MapPath("../")
    注:获得所在页面的上级目录。
    4、Server.MapPath("~/")
    注:获得当前应用级程序的目录,如果是根目录,就是根目录,如果是虚拟目录,就是虚拟目录所在的位置
      

  7.   

    回6楼,string  webPath的值是null,怎么写才能使它有值呢?
      

  8.   


    //string  webPath = System.Web.HttpContext.Current.Server.MapPath("") + @"\Web.config"; 
     string  webPath = System.Web.HttpContext.Current.Server.MapPath("Web.config");