利用Server.mapPath()取得網站相關路徑
'假設目前程式路徑:c:\Inetpub\wwwroot\myApp\subDir\subDir2\abc.aspx
'取得目前應用程式路徑,ex:c:\Inetpub\wwwroot\myApp\
Dim aaa As String = Server.MapPath("~\")
'取得目前應用程式路徑,ex:c:\Inetpub\wwwroot\myApp\
Dim bbb As String = Server.MapPath("~/")
'取得目前應用程式路徑,ex:c:\Inetpub\wwwroot\myApp\
Dim fff As String = Server.MapPath("~")
'取得根目錄路徑,ex:c:\Inetpub\wwwroot\
Dim ccc As String = Server.MapPath("/")
'取得目前頁面路徑,ex:c:\Inetpub\wwwroot\myApp\subDir\subDir2\
Dim ddd As String = Server.MapPath("./")
'取得目前頁面上一層路徑,ex:c:\Inetpub\wwwroot\myApp\subDir\
Dim eee As String = Server.MapPath("../")
'取得目前頁面上上一層路徑,ex:c:\Inetpub\wwwroot\myApp\
Dim hhh As String = Server.MapPath("../../")
補充一下,如果想要在類別檔.vb使用(而非aspx.vb),是沒有Server.mapPath可用的,要改成這樣用:
Imports System.Web
HttpContext.Current.Server.MapPath("xxx")