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.

Namespace: System.Web
Assembly: System.Web (in system.web.dll)

public string MapPath (
	string path
)
public String MapPath (
	String path
)
public function MapPath (
	path : String
) : String
Not applicable.

Parameters

path

The virtual path of the Web server.

Return Value

The physical file path that corresponds to path.

Exception typeCondition

HttpException

The current HttpContext is a null reference (Nothing in Visual Basic).

If path is a null reference (Nothing in Visual Basic), then the MapPath method returns the full physical path of the directory that contains the current application.

Security noteSecurity Note:

The MapPath method potentially contains sensitive information about the hosting environment. The return value should not be displayed to users.

The following 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.

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

String filePath;
filePath = get_Server().MapPath("/MyWebSite");

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

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Show: