Now some user information is saved in a file, like a simple database. Suppose there is a user who wants to know all visitors, and you need to log in
The relevant parts are separated from the recorded information because there is no structured column like a database.
We know that in the file created, line 1 is the username, line 2 is their homepage, and line 3 is their email address. Use for subsequent registration
The users also store their information in this structure, so every 3 lines will contain one user's registration information. Knowing this, you can write the following code to display it
Show 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)< -- 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
%>
This is just a very simple output, but you can include table or DHTML form information according to the situation.
If the file has been correctly created and written, the small loop above will properly list the information of everyone in the database. ReadLine method reads 1
Line contents until a newline is encountered, the subsequent ReadLine call will read the next line. AtEndOfStream is a property of a TextStream object, which tells us when
Encounter the end of the file.
Assume that for some reason we are not forming the file correctly, if a user has only 2 lines of information instead of 3 lines, then some errors will occur. us
The loop here retrieves the next 3 lines of information in the file. If there is no more than 3 lines of information, the following error message will appear:
Server object error 'ASP 0177 : 800a003e'
Therefore, be sure to add some error handling code to prevent unnecessary lines from being inserted into the file or the necessary line information is missing.