|
|
|
How to read from a text file using FileSystemObject.
This example shows you how to read from a text file in
an ASP page using the FileSystemObject.
<%
Option Explicit
' Set up constants
Const ForReading =
1
Const Create = False
' Declare local variables
Dim objFSO ' FileSystemObject
Dim TS ' TextStreamObject
Dim strLine ' local variable to store Line
Dim strFileName ' local variable to store fileName
strFileName = Server.MapPath("textfile.txt")
' Instantiate the FileSystemObject
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
' use Opentextfile Method to Open
the text File
Set TS = objFSO.OpenTextFile(strFileName,
ForReading, Create)
If Not TS.AtEndOfStream Then
Do While Not TS.AtendOfStream
strLine = TS.ReadLine
' Read one line at a time
Response.Write strLine
' Display that line
Response.Write "<br>"
Loop
End If
' close TextStreamObject
' and destroy local variables to
relase memory
TS.Close
Set TS = Nothing
Set objFSO = Nothing
%>
|
Have Questions? Discuss this topic in Dev
Forum
|
|
|
|
|
|