.NET Framework 類別庫
HttpServerUtility..::.MapPath 方法

更新:2007 年 11 月

傳回在 Web 伺服器上對應至指定虛擬路徑的實體檔案路徑。

命名空間:  System.Web
組件:  System.Web (在 System.Web.dll 中)

語法

Visual Basic (宣告)
Public Function MapPath ( _
    path As String _
) As String
Visual Basic (使用方式)
Dim instance As HttpServerUtility
Dim path As String
Dim returnValue As String

returnValue = instance.MapPath(path)
C#
public string MapPath(
    string path
)
Visual C++
public:
String^ MapPath(
    String^ path
)
J#
public String MapPath(
    String path
)
JScript
public function MapPath(
    path : String
) : String

參數

path
型別:System..::.String

Web 伺服器上的虛擬路徑。

傳回值

型別:System..::.String

對應至 path 的實體檔案路徑。

例外狀況

例外狀況條件
HttpException

目前的 HttpContextnullNothingnullptrNull 參照 (即 Visual Basic 中的 Nothing)

備註

如果 pathnullNothingnullptrNull 參照 (即 Visual Basic 中的 Nothing),則 MapPath 方法會傳回含有目前應用程式之目錄的完整實體路徑。

安全性注意事項:

MapPath 方法可能會包含與裝載環境有關的敏感性資訊。傳回值不應該顯示給使用者。

範例

下列範例會傳回含有指定網站之虛擬目錄的實體路徑。若要讀取程式碼後置模組中的 MapPath,請使用 HttpContext.Current.Server.MapPath

Visual Basic
Dim FilePath As String
FilePath = Server.MapPath("/MyWebSite")

C#
String FilePath;
FilePath = Server.MapPath("/MyWebSite");

J#
String filePath;
filePath = get_Server().MapPath("/MyWebSite");
JScript
var filePath : String = Server.MapPath("/MyWebSite")

平台

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求

版本資訊

.NET Framework

支援版本:3.5、3.0、2.0、1.1、1.0
請參閱

參考

標記 :


Page view tracker