ASP读取显示TXT文件内容

<html><head><title>基于文本的消息发布系统</title></head>
<body>
<table border="1" cellspacing="0" cellpadding="1" bordercolorlight="#dfdfdf" bordercolordark="#ffffff" align="center">
<tr bgcolor="#cccce6">
<td algin="center" colspan="2">最新消息</td>
</tr>
<%
Set fso=Server.CreateObject("ing.FileSystemObject")
Set fp=fso.OpenTextFile(Server.MapPath("message.txt"))
'打开message.txt

Do While fp.AtEndOfStream<>true
s
=fp.ReadLine '读取一条数据

p
=Instr(s,"*"'取得*号的位置
Messagetitle=Mid(s,1,p-1'取得*号前边的字符串(消息标题)
s=Mid(s,p+1,Len(s)-p) '设变量s为*号后边的字符串

p
=Instr(s,"*")
MessageUrl
=Mid(s,1,p-1'取得*号后边的字符串(链接地址)
s=Mid(s,p+1,Len(s)-p)

ttime
='设定消息发布时间ttime为s
%>
<tr>

<td><href='<%=MessageUrl%>'><%=Messagetitle%></a></td>
<td><%=ttime%></td>
</tr>
<!--生成表格,把消息显示出来-->
<%
Loop
Fp.close
Set fp=Nothing
Set fso=Nothing
%>
</table>
</body></html>

简单的方法
<%
dim fso,f
    
set fso=server.CreateObject("Scripting.FileSystemObject")
    
Set f =  fso.OpenTextFile(Server.MapPath("1.txt"),1)  
    
Do  While  Not  f.AtEndOfStream    
    response.write f.readline
    
loop
    f.close
    
set f=nothing
    
set fso=nothing
%>
posted @ 2007-12-23 15:45  胡枫  阅读(3605)  评论(0编辑  收藏  举报