The Magic function of the FSO in ASP-file read

Source: Internet
Author: User
Tags error handling readline
FSO Author: Gan Ganping

Now there are some user information saved in the file, just like a simple database. Suppose a user wants to know all of the visitors, from the login
Separate the related parts from the information in the note, because there is no structured column like a database.

We know that in the file created, line 1th is user name, line 2nd is their home page, and line 3rd is their e-mail address. subsequently registered with
Households also store their information according to such a structure, so every 3 rows will contain a user's registration information. Knowing these, you can write the following code to display
Show Information:

<%
' Create ' the FSO object
Set fso = Server.CreateObject ("Scripting.FileSystemObject")
Path = "C:emp est.txt"

' Open ' file
Set file = Fso.opentextfile (path, 1) <-for
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
%>

There's only a very simple output here, but you can include tables or DHTML form information depending on the situation.

If the file has been correctly created and written, the small loop above will properly list the information for each person in the database. ReadLine method reads 1
Line content until a newline character is encountered, subsequent ReadLine calls will read the next line. AtEndOfStream is the property of the TextStream object, and it tells us when
The tail of the file is encountered.

Suppose, for some reason, we did not form the file correctly, if a user had only 2 lines of information instead of 3 lines, there would be some errors. We
Here's a loop to retrieve the next 3 lines of information in the file, if there is no more than 3 rows of information, you will receive the following error message:

Server object error ' ASP 0177:800a003e '

Therefore, be sure to add some error handling code to prevent the file from inserting extra rows or missing the necessary line information.



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.