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.