How do I read the contents of a text file?

Source: Internet
Author: User
Tags servervariables variable
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.