How to read the contents of a text file

Source: Internet
Author: User
Tags servervariables


Ever want to know you to display the contents of a text document using ASP. Here's 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 the 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 the is I 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 I'll paste it into your code editor.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.