How to open a text file with success ?!

Results 1 to 3 of 3

Thread: How to open a text file with success ?!

  1. #1
    Join Date
    Dec 1969
    Posts
    108

    Default How to open a text file with success ?!

    I am trying to simply read a .txt file with the ReadLine command which I discovered on this site. It does not seam to be working. It works perfectly on my win98 machine running IIS4. But when I transfer all the files onto the winNT4 server running IIS3, it gets stuck in the loop. I do think that the problem is from the ReadLine, since the Textstream is empty before it enters the loop. I think that it is not reading the txt file like it should.<BR><BR>How do I test if it successfully finds and opens the .txt file?<BR><BR>Here is a part of the code:<BR>&#039==================================== ======<BR>on Error Resume Next <BR>Set conn = CreateObject("adodb.connection")<BR>conn.open "rapport"<BR><BR>Const ForReading = 1, ForWriting = 2, ForAppending = 8 <BR>set fso = Server.CreateObject("scripting.FileSystemObject")< BR>set f = fso.GetFile("c:Inetpubscripts estmyfile.txt")<BR>set ts = f.OpenAsTextStream(ForReading, -2)<BR>TextStreamTest = ts.ReadLine<BR><BR>&#039--- here when "TextStreamTest" is printed out, it is EMPTY ---<BR><BR>Do While not ts.AtEndOfStream<BR> TextStreamTest = ts.ReadLine<BR><BR> &#039--- IT GETS STUCK IN HERE ---<BR> &#039..........other operations here....<BR>Loop<BR>conn.close<BR>&#039...<BR>&#03 9==========================================<BR><BR >P.S. the "mytext.txt" file resides in the<BR>---&#062; c:Inetpubscripts est &#060;--- directory<BR><BR>ANY help would be very much appreciated.

  2. #2
    Join Date
    Dec 1969
    Posts
    778

    Default RE: How to open a text file with success ?!

    I got one to work just fine. It has a few less lines than yours.<BR><BR>set fs = creatobject("scripting.filesystemobject")<BR>mypat h = "c:inetpubwwwroot est.txt"<BR>set myfile = fs.opentextfile(mypath)<BR>do while not myfile.atendofstream<BR> sdata = sdata & myfile.readline<BR>loop<BR>set fs = nothing<BR>set myfile = nothing<BR><BR><BR>I hope this helps.<BR>

  3. #3
    suresh Guest

    Default RE: How to open a text file with success ?!

    here is the code to read text files<BR>SET FileSystem=Server.CreateObject("Scripting.FileSyst emObject")<BR>Filename="text.txt"<BR>Default=FileS ystem.GetSpecialFolder(SystemFolder)<BR>Drive=File System.GetDriveName(Default) &#039// driver name<BR>&#039//open file by mentioning the folderpath<BR>set myfileobject=FileSystem.OpenTextFile(Drive & "Inetpubwwwroot ext\" &Filename)<BR>do until myfileobject.atendofstream<BR> Lineval=trim(myfileobject.readline) &#039 read each line from the file<BR>exit do<BR>loop<BR>myfileobject.close<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •