ASP Programming Essentials ABC
Using Server.MapPath
Use Server.MapPath () as much as possible to represent files stored on the server, rather than static absolute paths. Because, if you take a static absolute path, when the Web path changes, it will cause the file path to express errors, and therefore have to modify the original static path. The path represented by the Server.MapPath () does not have to be modified.
For example, the following code is not a good method:
<%
Whichfile= "D:\inetpub\wwwroot\whatever\junk.txt"
Set fs = CreateObject ("Scripting.FileSystemObject")
Set thisfile = fs. OpenTextFile (Whichfile, 1, False)
Tempstr=thisfile.readall
Response.Write TempStr
Thisfile. Close
Set thisfile=nothing
Set fs=nothing
% >
It is recommended that you use the following code to accomplish the same function:
<%
Whichfile=server.mappath ("\whatever\junk.txt")
Set fs = CreateObject ("Scripting.FileSystemObject")
Set thisfile = fs. OpenTextFile (Whichfile, 1, False)
Tempstr=thisfile.readall
Response.Write TempStr
Thisfile. Close
Set thisfile=nothing
Set fs=nothing
% >