MapPath Method (String)
Collapse the table of content
Expand the table of content

HttpRequest.MapPath Method (String)

 

Maps the specified virtual path to a physical path.

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

member MapPath : 
        virtualPath:string -> string

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.

Exception Condition
HttpException

No HttpContext object is defined for the request.

System_CAPS_cautionCaution

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
Available since 1.1
Return to top
Show:
© 2016 Microsoft