更新:2007 年 11 月
返回与 Web 服务器上的指定虚拟路径相对应的物理文件路径。
命名空间:
System.Web 程序集:
System.Web(在 System.Web.dll 中)
Public Function MapPath ( _
path As String _
) As String
Dim instance As HttpServerUtility
Dim path As String
Dim returnValue As String
returnValue = instance.MapPath(path)
public string MapPath(
string path
)
public:
String^ MapPath(
String^ path
)
public String MapPath(
String path
)
public function MapPath(
path : String
) : String
如果 path 为 nullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing),MapPath 方法将返回包含当前应用程序的目录的完整物理路径。
安全说明: |
|---|
MapPath 方法很可能包含有关宿主环境的敏感信息。不应向用户显示返回值。 |
下面的示例返回包含指定网站的虚拟目录的物理路径。若要读取代码隐藏模块中的 MapPath,请使用 HttpContext.Current.Server.MapPath。
Dim FilePath As String
FilePath = Server.MapPath("/MyWebSite")
String FilePath;
FilePath = Server.MapPath("/MyWebSite");
String filePath;
filePath = get_Server().MapPath("/MyWebSite");
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
参考