The magic of FSO in ASP-File Reading

Source: Internet
Author: User

Author: Gan jiping

Now some user information is saved in a file, just like a simple database. Assume that a user wants to know all the visitors

Separated from the information, because there is no structured column like a database.

We know that in the created file, row 1st is the user name, row 2nd is their home page, and row 3rd is their email address. Subsequent Registration

Users store their information according to this structure, so every 3 rows contains a user's registration information. You can write the followingCodeLaixian

Display Information:

<%

'Create the FSO object

Set FSO = server. Createobject ("scripting. FileSystemObject ")

Path = "C: EMP est.txt"

'Open the file

Set file = FSO. opentextfile (path, 1) <--

Reading

Next, analyze each row and format the data:

Do until file. atendofstream

Response. Write ("name:" & file. Readline &"")

Response. Write ("Home Page:" & file. Readline &"")

Response. Write ("Email:" & file. Readline & "<p> ")

Loop

'Close and clean up

File. Close

Set file = nothing

Set FSO = nothing

%>

Only a simple output is provided here, but you can include the table or DHTML form information as needed.

If a file has been correctly created and written, the above small loop will properly list the information of everyone in the database. Readline method read 1

Line content until a line break is encountered, the subsequent Readline call will read the next line. Atendofstream is the property of the textstream object. It tells us when

The end of the file.

Assume that, for some reason, the file is not correctly formed. If a user only has two lines of information instead of three lines, some errors will occur. We

Here, the next three lines of information in the file are retrieved cyclically. If there are no more than three lines of information, the following error message will appear:

Server Object error 'asp 0177: 800a003e'

Therefore, you must add some error processing code to prevent unnecessary rows or unnecessary row information from being inserted in the file.

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.