This documentation is archived and is not being maintained.

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
public string MapPath(
 string path
public: String* MapPath(
 String* path
public function MapPath(
   path : String
) : String;


The virtual path on the Web server.

Return Value

The physical file path that corresponds to path.


Exception Type Condition
HttpException The Server object is not available.


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


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")

String FilePath;
FilePath = Server.MapPath("/MyWebSite");

String* FilePath;
FilePath = Server->MapPath(S"/MyWebSite");

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


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

See Also

HttpServerUtility Class | HttpServerUtility Members | System.Web Namespace