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



The virtual path on the Web server.

Return Value

The physical file path that corresponds to path.

Exception typeCondition


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 to the directory containing the current application.

Caution noteCaution

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

The following code 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 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions