动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   Asp → 阅读文章

 怎样读取一个文本文件的内容

作者来源: 
阅读 1248 人次 , 2006-4-3 0:04:00 


ever want to know how to display the contents of a text document using asp. here is a easy way to read
from a text file

<!--start of asp code---->

<%
'by james seymour, http://jamesdot.org

dim write
dim filesysobj, tf, read

' read the read.txt

' store the file name where the information is stored into a variable called read

read = "read.txt"

' retrieve the fullpath of the read file

read = left(server.mappath(request.servervariables("path_info")), instrrev(server.mappath
(request.servervariables("path_info")), "\")) & read

' create an instance of filesystem object and store it into a variable called filesysobj

set filesysobj = createobject("scripting.filesystemobject")

' check whether the read file exists

if (filesysobj.fileexists(read)) then
' if the file exists, then open it for reading
set tf = filesysobj.opentextfile(read, 1)
read = tf.readline
tf.close
else
' if you can't find read.text, display default message
read = "i can't find the file read.txt! so this is my default message."

end if
%>

' table the displays the read.txt file
<div align="center">
<center>
<table border="0" width="40%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" bgcolor="#eeeecc"><b><%=read%></b>
</td>
</tr>
<tr>
<td width="100%">

<!-- end of the asp -->

use the code above, click and drag your mouse over the code to highlight it. then right click on the
highlighted code and click "copy." now you may paste it into your code editor.

 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:用ASP做一个TOP COOL的站内搜索
· 下一篇:在线用表单建立文件夹
· 如何使用ASP制作类似安装向导的页面?
· 一个新的JMail(4.3版本)发送代码
· ASP实用大全-ASP对象(2)
· 在ASP中使用SQL语句之2:用WHERE子句设置查询条件
· 论坛树状记录表的堆栈展开


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077