ASP has been through a period of time, I would describe the use of ASP FSO to achieve file read and write operations, there is a need to learn friends can refer to.
1.AtEndOfStream
This property indicates whether the end of the entire text file has been reached. Its value is "TRUE" or "FALSE"
2.CreateTextFile
Used to create a new text file
Parameters in the 3.OpenTextFile () method
Written by Saucer (Shi):
The code is as follows |
|
Set f = fso. OpenTextFile ("C:testfile.txt", ForWriting, True) |
The ForWriting value is 2, which means that a writable text file is opened
is 1, which means that a readable text file is opened
Is 8, indicating that you want to append data
True indicates that if this file is not in place, a new
This argument can choose True or false to indicate whether the file is created when it does not exist
Instance 1
Read the file:
The code is as follows |
|
<% Set Myfileobject=server.createobject ("Scripting.FileSystemObject") Set Mytextfile=myfileobject.opentextfile ("C:mydirtest.txt") While not Mytextfile.atendofstream Response.Write (Mytextfile.readline) Wend Mytextfile.close %> |
Write file:
The code is as follows |
|
<% Set Myfileobject=server. CreateObject ("Scripting.FileSystemObject") Set Mytextfile=myfileobject. CreateTextFile ("C:mydirtest.txt") Mytextfile. WriteLine Mytextfile.close %> |
Instance 2
FSO to create the simplest access counter
The code is as follows |
|
<% Set Fs=server.createobject ("Scripting.FileSystemObject") File = Server.MapPath ("Counter.txt") Set txtr = fs. OpenTextFile (File,1,true) ' opens a read-only file, or if it does not exist, creates a new Counter=0 ' The counter to zero If not Txtr.atendofstream Then ' first determine where the end is not reached line = txtr. ReadLine ' reads a row of data Else Line=0 ' Otherwise set initial value to 0 End If Counter=line+1 ' Count plus 1 Set txtw = Fs.opentextfile (file,2,true) ' Open write-only files file Txtw.write counter ' write count Response. Write ("<center> you are the first <b>" &counter& "</b> Guest! </center> ") ' Output count %> |
This document can be introduced as include in places where statistics and display counts are required.
The code is as follows |
|
<!--#include file= "counter.asp"--> |
However, if it is a static page such as HTML, you can use this simple counter in the form of script scripting.
So counter.asp needs to write that.
The code is as follows |
|
<% Response. Write ("document.write" <center> you are the first <b> "&counter&" </b> Guest! </center> ""); %> |
You can use counters using script scripts in HTML static pages that need to be referenced:
code is as follows |
&nbs P; |
<script src= "counter.asp" ></SCRIPT> |