如果数据足够简单是可以考虑使用文本数据的。
在ASP中,要进行文件的存取必须先建立FileSystemObject对象, 再用建立出来的这个文件对象来进行文件各项操作,用法:
set fileobject=server.createObject(“scripting.FileSystemObject”),
用createTextFile来建立文本文件:
set 文件对象名=filesystemObject 对象名.createTextFile
用OpenTextFile来打开文件
set 文件对象名=filesystemObject 对象名.OpenTextFile
接下来就是文件的读写了,用ReadLine和WriteLine方法来逐行读写,
用ReadAll方法来读取全部内容,另外还会用到MoveFile来更改文件,
它的作用是复制一个文件名称不同而数据相同的文件,
当然你可以用CopyFile来复制,但这只能将一个文件复制成另一个文件,
最后再来说说deleteFile,用法:
文件对象名.deleteFile 路径 文件名
在本例中只需两个页面:index.asp
显示留言
显示留言
2、处理页面:add.asp
<%
name = Request("name")
textmemo=Request("textmemo")
If name = "" Or textmemo = "" Then
Response.Write ""
Response.End
End If
'以下为读入数据的处理,先将计入的栏位数据改写成
'HTML形式以方便直接调用
Line1 = "昵 称:" & name & " "
textmemo = Replace( textmemo, vbCrLf, "BR" )'把换行字符vbcrlf取代为
Line2 ="内 容:" & textmemo
On Error Resume Next
Set fileobject = Server.createObject("Scripting.FileSystemObject")
Application.Lock '避免两们或两们以上的连接同时进行网页链接
FilePath = Server.MapPath("information.txt")'取得完整的路径
OldFilePath = Server.MapPath("oldinfo.txt")
fileobject.MoveFile FilePath, OldFilePath'将information.txt更名复制为oldinfo.txt
Set TEMP = fileobject.OpenTextFile(OldFilePath, , True)'打开oldinfo.txt
Set newmessage = fileobject.createTextFile(FilePath)'建立information.txt
newmessage.WriteLine Line1
newmessage.WriteLine Line2
newmessage.WriteLine " "
newmessage.WriteLine TEMP.ReadAll'一次读取整个oldinfo.txt的内容写入
TEMP.Close
fileobject.deleteFile OldFilePath, True'删除oldinfo.txt
Application.UnLock
Response.Redirect "index.asp"
%>
|