複製鏈接
請複製以下鏈接發送給好友

MapPath

鎖定
MapPath是返回與 Web 服務器上的一種方法,其命名空間為 System.Web。
外文名
MapPath
命名空間
System.Web
程序集
System.Web
MapPath返回與 Web 服務器上的指定虛擬路徑相對應的物理文件路徑的一種方法。
程序集: System.Web(在 System.Web.dll 中)
語法
Visual Basic(聲明)
Public Function [font id=baidubar_0 style="COLOR: black; BACKGROUND-COLOR: #ffff66"][font]MapPath[/font][/font] ( _path As String _) As String
Visual Basic (用法)
Dim instance As HttpServerUtility
Dim path As String
Dim returnValue As String
returnValue = instance.[font id=baidubar_0 style="COLOR: black; BACKGROUND-COLOR: #ffff66"][font]MapPath[/font][/font](path)
C#
public string [font id=baidubar_0 style="COLOR: black; BACKGROUND-COLOR: #ffff66"][font]MapPath[/font][/font](string path)
Visual C++
public:
String^ [font id=baidubar_0 style="COLOR: black; BACKGROUND-COLOR: #ffff66"][font]MapPath[/font][/font](String^ path)
J#
public String [font id=baidubar_0 style="COLOR: black; BACKGROUND-COLOR: #ffff66"][font]MapPath[/font][/font](String path)
JScript
public function [font id=baidubar_0 style="COLOR: black; BACKGROUND-COLOR: #ffff66"][font]MapPath[/font][/font](path : String) : String
參數
path
類型:System..::.String
Web 服務器的虛擬路徑
返回值
類型:System..::.String
與 path 相對應的物理文件路徑。
異常 :
異常 條件
HttpException 當前 HttpContext 為 nullNothingnullptrnull 引用(在 Visual Basic 中為 Nothing)。
備註
如果 path 為 nullNothingnullptrnull 引用(在 Visual Basic 中為 Nothing),[font id=baidubar_0 style="COLOR: black; BACKGROUND-COLOR: #ffff66"][font]MapPath[/font][/font] 方法將返回包含當前應用程序的目錄的完整物理路徑。
安全説明:
[font id=baidubar_0 style="COLOR: black; BACKGROUND-COLOR: #ffff66"][font]MapPath[/font][/font] 方法很可能包含有關宿主環境的敏感信息。不應向用户顯示返回值。
示例 :
下面的示例返回包含指定網站的虛擬目錄的物理路徑。若要讀取代碼隱藏模塊中的 [font id=baidubar_0 style="COLOR: black; BACKGROUND-COLOR: #ffff66"][font]MapPath[/font][/font],請使用 HttpContext.Current.Server.[font id=baidubar_0 style="COLOR: black; BACKGROUND-COLOR: #ffff66"][font]MapPath[/font][/font]。
Visual Basic :
Dim FilePath As String
FilePath = Server.[font id=baidubar_0 style="COLOR: black; BACKGROUND-COLOR: #ffff66"][font]MapPath[/font][/font]("/MyWebSite")
C# :
String FilePath;
FilePath = Server.[font id=baidubar_0 style="COLOR: black; BACKGROUND-COLOR: #ffff66"][font]MapPath[/font][/font]("/MyWebSite");
J# :
String filePath;
filePath = get_Server( ).[font id=baidubar_0 style="COLOR: black; BACKGROUND-COLOR: #ffff66"][font]MapPath[/font][/font]("/MyWebSite");
JScript :
var filePath : String = Server.[font id=baidubar_0 style="COLOR: black; BACKGROUND-COLOR: #ffff66"][font]MapPath[/font][/font]("/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