程序
default.asp
-------------------------------
<HTML><BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<B>This is my guestbook. Use this form to submit your greeting:</B><BR>
<FORM METHOD="POST" ACTION="write.asp">
<INPUT NAME="new_line" TYPE="TEXT" SIZE=35>
<INPUT TYPE="SUBMIT" VALUE="Add greeting">
</FORM>
<BR><BR>
<%
MyFile = "c:\guestbook.txt"
'Opens the guestbook file if it exists
Set MyFileObj=Server.CreateObject("Scripting.FileSystemObject")
IF MyFileObj.FileExists(MyFile) THEN
Set MyTextFile=MyFileObj.OpenTextFile(MyFile)
'Reads a line, and outputs it
WHILE NOT MyTextFile.AtEndOfStream
%>
<HR>
<%=MyTextFile.ReadLine%>
</HR>
<%
WEND
'Closes the textfile
MyTextFile.Close
END IF' Does file exist
%>
<HR>
</BODY>
</HTML>
----------------------------
write.asp
----------------------------
<%
'Type in the path of the file to use. Make sure that the script has write access.
MyFile = "c:\guestbook.txt"
'Ready Scripting.FileSystemObject
Set MyFileObj=Server.CreateObject("Scripting.FileSystemObject")
'Opens textfile. 8 = add line to file, true = create if it doesn't exists
Set MyOutStream=MyFileObj.OpenTextFile(MyFile, 8, TRUE)
'Writes the line to the file
New_line = Request.Form("new_line")
New_line = Server.HTMLEncode(New_line)
'Adds the time and date it was posted
New_line = "<I>Posted: " & NOW & "</I><BR>" & New_line
MyOutStream.WriteLine(New_line)
'Closes the file
MyOutStream.Close
'Sends them back to the default page
Response.Redirect "default.asp"
%>