Finding a file's physical path with the virtual path
If you're working with an ISP, you don't always know the physical path to the files you upload. ISPs typically provide you with a 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 pathit'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 of the ASP server object.
Among other things, the Server.MapPath method takes the virtual path as an argument and returns the file's physical path and filename. Here's the syntax:
Server.MapPath("/virtualpath ")
For example, if 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 your own ASP files. Open an ASP page in UltraDev, switch to Code view (View > Code), and insert a <%Response.Write( stringvariable )%> expression in a page's HTML code using a valid Server.MapPath expression for the stringvariable expression. Here's an example:
<% Response.Write(Server.MapPath("/jsmith/index.htm")) %>
Next, switch back to Design view (View > Design) and turn on 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 in this article, the page would display the following physical path:
c:\Inetpub\wwwroot\accounts\users\jsmith\index.htm
For more detailed information on the Server.MapPath method, consult the online documentation that comes with Microsoft IIS or Personal Web Server.
|