ASP Programming Essentials ABC One

Source: Internet
Author: User
Programming 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

% >



Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.