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 MapPath
method.
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:
Server.MapPath("/virtualpath
")
Suppose a files 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.
<%Response.Write(stringvariable
)%>
MapPath
method to obtain a value for the stringvariable
argument.
Heres an example:
<% Response.Write(Server.MapPath("/jsmith/index.htm")) %>
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.