帝国软件
  设为首页 加入收藏 关于我们
 
解密帝国网站管理系统
栏 目:
 
您的位置:首页 > 技术文档 > ASP编程
怎样读取一个文本文件的内容? 
作者: 发布时间:2005-03-12 来源:
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里面创建统计图表  (2005-03-12)
 ·怎样判断一个盘上是否有文件  (2005-03-12)
 ·怎样传送更多的数据在表单中  (2005-03-12)
 ·用asp怎样编写文档搜索页面(1)  (2005-03-12)
 ·用asp怎样编写文档搜索页面(2)  (2005-03-12)
 ·用asp怎样编写文档搜索页面(3)  (2005-03-12)
 ·用asp怎样编写文档搜索页面(4)  (2005-03-12)
 ·用asp怎样编写文档搜索页面(5)  (2005-03-12)
 ·用asp怎样编写文档搜索页面(6)  (2005-03-12)
 ·怎样把数据库结构显示出来的源代  (2005-03-12)

   栏目导行
  PHP编程
  ASP编程
  ASP.NET编程
  JAVA编程
   站点最新
·致合作伙伴的欢迎信
·媒体报道
·帝国软件合作伙伴计划协议
·DiscuzX2.5会员整合通行证发布
·帝国CMS 7.0版本功能建议收集
·帝国网站管理系统2012年授权购买说
·PHPWind8.7会员整合通行证发布
·[官方插件]帝国CMS-访问统计插件
·[官方插件]帝国CMS-sitemap插件
·[官方插件]帝国CMS内容页评论AJAX分
   类别最新
·在ASP中使用数据库
·使用ASP脚本技术
·通过启动脚本来感受ASP的力量
·学习使用ASP对象和组件
·解析asp的脚本语言
·初看ASP-针对初学者
·ASP开发10条经验总结
·ASP之对象总结
·ASP与数据库应用(给初学者)
·关于学习ASP和编程的28个观点
 
关于帝国 | 广告服务 | 联系我们 | 程序开发 | 网站地图 | 留言板 帝国网站管理系统