我想写一个类库,里面需要取得一个相对于根目录的xml文件里的一些设置参数,请问在类库李怎么取得网站根的物理路径?
谢谢。

解决方案 »

  1.   

    string XmlFile = HttpContext.Current.Server.MapPath("~/Message.xml");
      

  2.   

    System.Web.HttpContext.Current.Request
      

  3.   

    System.Web.HttpContext.Current.Request.PhysicalApplicationPath
      

  4.   

    System.Web.HttpContext.Current.Server.MapPath("~/");
      

  5.   

    string appRoot =  System.Web.HttpContext.Current.Server.MapPath("~/");
      

  6.   

    string url = HttpContext.Current.Server.MapPath("fileUrl");
      

  7.   

    1、HttpContext.Current.Server.MapPath("~/Message.xml");
    上面的被限制之后我会用下面的:
    2、System.Web.HttpContext.Current.Request.PhysicalApplicationPath+"文件夹\文件名"
    下面的
    HttpContext.Current.Server.MapPath("~")== System.Web.HttpContext.Current.Request.PhysicalApplicationPath
      

  8.   

    HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath+"//Message.xml");
      

  9.   

    System.Web.HttpContext.Current.Request.PhysicalApplicationPath
      

  10.   

    HttpContext.Current.Server.MapPath("~");
      

  11.   

    Server.MapPath
    我就知道进来回答的一堆,我纯接分
      

  12.   

    System.Web.HttpContext.Current.Request.PhysicalApplicationPath
    这个比Server.mapth好很多 。后者是根据你具体在哪个文件夹里面引用,得到目录根文件夹的物理路径,而不是真实的网站根目录
      

  13.   

    我觉得在类库中不要用System.Web.HttpContext.Current.Request比较好,还是把路径作为参数传进去,这样 web 和win 可以一起共用这个类库。
      

  14.   

    HttpContext.Current.Server.MapPath(strPath);