Export (0) Print
Expand All

HttpRequest::MapPath Method (String)

Maps the specified virtual path to a physical path.

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

public:
String^ MapPath(
	String^ virtualPath
)

Parameters

virtualPath
Type: System::String
The virtual path (absolute or relative) for the current request.

Return Value

Type: System::String
The physical path on the server specified by virtualPath.

ExceptionCondition
HttpException

No HttpContext object is defined for the request.

Caution noteCaution

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

The following code example uses the MapPath method to convert a virtual path to a fully qualified physical path on the server. This example has two parts:

  • An .aspx page maps the path, reads the file, and displays results of the read operation.

  • A class, UpperCaseFilterStream, that changes all characters passed through it to uppercase.

The first part of the example shows how to convert a virtual path to a fully qualified physical path using the MapPath method. This physical path is then passed to a StreamReader object, which obtains the contents of the file. The Write method is then called to display the content of the file on the page. The Filter property is used to attach a filter to the response stream that makes the text displayed to the page all uppercase.

No code example is currently available or this language may not be supported.

The second part of the example shows a class that inherits from Stream and converts all characters in a stream to uppercase. Put this code in the App_Code folder for your application.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Community Additions

ADD
Show:
© 2014 Microsoft