Finding a file’s physical path with the virtual path

Finding a file’s physical path with the virtual path

If you work with an ISP, you don’t 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 file’s virtual path--it’s the path that follows the server or domain name in a URL. Once you know the virtual path, you can get the file’s physical path on the server using the MapPath method.

Among other things, the MapPath method takes the virtual path as an argument and returns the file’s physical path and filename. Here’s the method’s syntax:

Server.MapPath("/virtualpath")

Suppose a file’s virtual path is /jsmith/index.htm, then the following expression will return its physical path:

Server.MapPath("/jsmith/index.htm")

You can experiment with the MapPath method as follows.

  1. Open an ASP page in Dreamweaver and switch to Code view (View > Code).
  2. Enter the following expression in the page’s HTML code.
    <%Response.Write(stringvariable)%>
    
  3. Use the MapPath method to obtain a value for the stringvariable argument.

    Here’s an example:

    <% Response.Write(Server.MapPath("/jsmith/index.htm")) %>
    
  4. 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:

    c:\Inetpub\wwwroot\accounts\users\jsmith\index.htm
    

For more information on the MapPath method, consult the online documentation that comes with Microsoft IIS.

Related topics

  • Understanding physical and virtual paths
  • Using a virtual path to connect to a database


Getting Started with Dreamweaver
Dreamweaver Basics
Working with Dreamweaver Sites
Laying Out Pages
Adding Content to Pages
Working with Page Code
Preparing to Build Dynamic Sites
Making Pages Dynamic
Developing Applications Rapidly
 
ASPTreeView.com
 
Evaluation has ¶·Рј»ТСјЅМЕexpired.
Info...