Articles
DevASP - ASP and XML Articles, Samples, Toturials, Sample Chapters and resources for Developers Saturday, February 04, 2012
Home
Articles & Samples
Dev Search
Sample Chapters
Link to US
Contact
Search Directory
Applications
Articles & Samples
Components
Community
Database
Developer Sites
Downloads
Hosting Services
Introduction
Knowledge Base
Sample Chapters
WebCasts
ASP Directory
Applications
Articles & Samples
Components
Developer Sites
Knowledge Base
Sample Chapters
WebCasts
XML Directory
Applications
Articles & Samples
Developer Sites
Error, Bugs & Fixes
Downloads
Introduction
Knowledge Base
Sample Chapters
WebCasts

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
%>
Back to ASP Samples

DevASP - Privacy - Disclaimer
Copyright © 2008 DevASP.com