Export (0) Print
Expand All

HttpServerUtility.MapPath Method

Returns the physical file path that corresponds to the specified virtual path on the Web server.

[Visual Basic]
Public Function MapPath( _
   ByVal path As String _
) As String
[C#]
public string MapPath(
 string path
);
[C++]
public: String* MapPath(
 String* path
);
[JScript]
public function MapPath(
   path : String
) : String;

Parameters

path
The virtual path on the Web server.

Return Value

The physical file path that corresponds to path.

Exceptions

Exception Type Condition
HttpException The Server object is not available.

Remarks

If path is NULL, MapPath returns the full physical path to the directory containing the current application.

Example

The following page example returns the physical path of the virtual directory that contains the specified Web site. To read MapPath in a code-behind module, use HttpContext.Current.Server.MapPath.

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

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

[C++] 
String* FilePath;
FilePath = Server->MapPath(S"/MyWebSite");
   

[JScript] 
var filePath : String = Server.MapPath("/MyWebSite")
   

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

HttpServerUtility Class | HttpServerUtility Members | System.Web Namespace

Show:
© 2014 Microsoft