请单击以进行评分并提供反馈
MSDN
MSDN Library
.NET 开发
.NET Framework
 MapPath 方法

  开启低带宽视图
此页面仅适用于
Microsoft Visual Studio 2008/.NET Framework 3.5

同时提供下列产品的其他版本:
.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 中为 NothingMapPath 方法将返回包含当前应用程序的目录的完整物理路径。

安全说明:

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
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
© 2009 Microsoft Corporation 版权所有。 保留所有权利  |  商标  |  隐私权声明
Page view tracker