利用Server.mapPath()取得网站相关路径(HttpContext.Current.Server.MapPath,路径,根目录,目前应用程序,上一层,类,vb,HttpContext.Current.Server.MapPath))

利用Server.mapPath()取得网站相关路径


'假设目前程序路径:c:InetpubwwwrootmyAppsubDirsubDir2abc.aspx

'取得目前应用程序路径,ex:c:InetpubwwwrootmyApp
 Dim aaa As String = Server.MapPath("~") 

'取得目前应用程序路径,ex:c:InetpubwwwrootmyApp
        Dim bbb As String = Server.MapPath("~/") 

'取得目前应用程序路径,ex:c:InetpubwwwrootmyApp
        Dim fff As String = Server.MapPath("~") 

'取得根目录路径,ex:c:Inetpubwwwroot
        Dim ccc As String = Server.MapPath("/") 

'取得目前页面路径,ex:c:InetpubwwwrootmyAppsubDirsubDir2
        Dim ddd As String = Server.MapPath("./") 

'取得目前页面上一层路径,ex:c:InetpubwwwrootmyAppsubDir
        Dim eee As String = Server.MapPath("../") 

'取得目前页面上上一层路径,ex:c:InetpubwwwrootmyApp
        Dim hhh As String = Server.MapPath("../../") 

补充一下,如果想要在类档.vb使用(而非aspx.vb),是没有Server.mapPath可用的,要改成这样用:

Imports System.Web

HttpContext.Current.Server.MapPath("xxx")