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:inetpubwwwrootwhateverjunk.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 ("Whateverjunk.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
% >
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.