Articles   Dev Forums   Personalize   Favorites   Member Login   ASP Hosting      Active Users:  93
DevASP - ASP and XML Articles, Samples, Toturials, Sample Chapters and resources for Developers Friday, May 09, 2008
Home
Articles & Samples
ASP Hosting
Dev Search
Dev Forum
Add Your Articles
Add a Listing
Sample Chapters
Directory Feed
Link to US
Contact

Search Directory
Applications
Articles & Samples
Components
Community
Database
Developer Sites
Downloads
Hosting Services
Introduction
Knowledge Base
Sample Chapters
WebCasts

Trusted by over 7 million customers!
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
%>

Have Questions? Discuss this topic in Dev Forum

Back to ASP Samples
DevASP - Privacy - Disclaimer
Copyright © 2008 DevASP.com