Finding a files physical path with the virtual path
If you work with an ISP, you dont always know the physical path to the files you upload. ISPs typically provide you with an FTP host, possibly a host directory, and a login name and password. ISPs also specify a URL to view your pages on the Internet, such as www.plutoserve.com/jsmith/.
If you know the URL, then you can get the files virtual path--its the path that follows the server or domain name in a URL. Once you know the virtual path, you can get the files physical path on the server using the
Among other things, the
MapPath method takes the virtual path as an argument and returns the files physical path and filename. Heres the methods syntax:
Suppose a files virtual path is /jsmith/index.htm, then the following expression will return its physical path:
You can experiment with the
MapPath method as follows.
- Open an ASP page in Dreamweaver and switch to Code view (View > Code).
- Enter the following expression in the pages HTML code.
- Use the
MapPath method to obtain a value for the
Heres an example:
<% Response.Write(Server.MapPath("/jsmith/index.htm")) %>
- Switch to Design view (View > Design) and enable Live Data (View > Live Data) to view the page.
The page displays the physical path of the file on the application server. Using the example discussed in this section, the page displays the following physical path:
For more information on the
MapPath method, consult the online documentation that comes with Microsoft IIS.
- Understanding physical and virtual paths
- Using a virtual path to connect to a database