Reading the contents of a file

In our previous beginners example we created a text file and entered some text into out but what if we want to read the contents of the text file . In this example we show you how to read the data contained in a text file and display it.

Code :

<%
'declare our variables
Dim objFSO , objTextStream , counter_file , intCount
'create an instance of FileSystem object
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'the path to the file
counter_file = Server.MapPath("samplefile.txt")
'create instance of textstream object and open text file
Set objTextStream = objFSO.OpenTextFile(counter_file)
'display data in the text file
Do While Not objTextStream.AtEndOfStream
Response.Write objTextStream.ReadLine & "<br>"
Loop
'close textstream
objTextStream.Close
'destroy objects
Set objTextStream = Nothing
Set objFSO = Nothing
%>

 

Books

cover

Asp Developer's Guide (The Application..

. cover


Professional ASP .NET


cover


Asp Developer's Guide (The Application...