Name

MapPath

Synopsis

stringvar = Request.MapPath(virtualPath)
stringvar = Request.MapPath(virtualPath, _ 
             baseVirtualDirectory, allowCrossMapping)

The MapPath method, which the Server object exposed in classic ASP, allows you to retrieve a physical path on the server for a provided virtual path. In ASP.NET, this method is overloaded, meaning that it can be called with two different sets of arguments, as shown in the previous code. The first style, which is the same as in classic ASP, simply passes in a String containing the virtual path to be mapped. The second adds the baseVirtualDirectory argument, which specifies a base from which to resolve relative paths, and the allowCrossMapping argument, which allows you to map virtual paths that belong to other applications.

Parameters

stringvar

A String variable to receive the mapped physical path.

virtualPath

A String argument containing the virtual path to map.

baseVirtualDirectory

A String argument containing a base path to be used for resolving relative paths.

allowCrossMapping

A Boolean argument specifying whether paths can be mapped across applications.

Example

The example maps the path of the .NET Framework SDK samples’ /QuickStart directory and writes the result to the browser:

Sub Page_Load(  )
   Dim VirPath, PhysPath, BasePath As String
   Dim BoolCross As Boolean = True
  
   VirPath = "/QuickStart"
   BasePath = ""
  
   Message.Text = Request.MapPath(VirPath, BasePath, BoolCross)
End Sub

Notes

In the previous example, if we had set the BoolCross ...

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.