MapPath返回与 Web 服务器上的指定虚拟路径相对应的物理文件路径的一种方法。
命名空间: System.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
