devxlogo

Accessing Text File Data From ASP Pages

Accessing Text File Data From ASP Pages

Question:
Can I retrieve data from a text file instead of querying an Access database?

Answer:
Yes, you can access a text file from an ASP page. Use the FileSystemObject COM component that ships with IIS.

First, create a FileSystemObject object.

   Dim fs, f, strOneLine   Set fs = CreateObject("Scripting.FileSystemObject")

Next, create a TextStream Object out of the FileSysemObject.

   Set f = fs.OpenTextFile("c:	estfile.txt", 1,0)   ' -- in above code,   ' -- 1 = for reading   ' -- 0 = TriStateFalse

Read lines from the TextStream Object. Use the AtEndOfStream property to make sure you are not at end of file.

   Do While f.AtEndOfStream <> True          strOneLine = F.ReadLine          ' -- do something with your line   Loop

Finally, close all your objects.

   F.Close   Set f = Nothing   Set fs = Nothing

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist