Solved

Readline is reading entire text document

Posted on 2009-03-30
8
2,615 Views
Last Modified: 2012-05-06
I have two ASP Scripts. One creates a text file of data from a database. The second file calls that first file then opens the text file that it created.
 
  What I am struggling with is just gabbing the first line of the text file (it contains my column names). When I use ReadLine it is reading the entire text file and not just the first line. If I open the text file in notepad, all the data is on separate lines as it should be.
 
  So, I am thinking that I am either not writing the line feeds properly or I am not using the ReadLine method properly.
 
  The code is below (in the next two comments fields). The CreateFile.asp is the file that creates the data file. The GetData.asp file is the one that proccesses the file.

0
Comment
Question by:swinslow
  • 5
  • 3
8 Comments
 
LVL 4

Author Comment

by:swinslow
ID: 24022520
CreateFile.asp
 <%

  Server.ScriptTimeout = 9999

  Response.Expires = 0

  Response.Expiresabsolute = Now() - 1

  Response.AddHeader "pragma","no-cache"

  Response.AddHeader "cache-control","private"

  Response.CacheControl = "no-cache"

  Response.Buffer = False

  Response.ContentType = "text/tab-separated-values"

  Response.AddHeader "content-disposition", "inline; filename=SalesOrders.tsv"
 
 

  Set ObjFSO = Createobject("Scripting.FileSystemObject")

  Set objRS = Server.CreateObject ("ADODB.RecordSet")
 

  SqlStr = "SELECT * " & _

           "FROM SalesOrders " & _

           "ORDER BY SONum DESC "

  objrs.Open SqlStr, SOConStr, adOpenStatic, adLockOptimistic,adCmdText

  For Each ColumnName in Objrs.Fields

     Response.Write ColumnName.Name & chr(9)

  Next

  While Not Objrs.EOF

     'Create line feed

     Response.Write chr(13) & chr(10)

     For Each ColumnName in Objrs.Fields

        Response.Write ColumnName.value & chr(9)

     Next

  Objrs.MoveNext

  Wend

  objrs.Close

  
 

  Set objrs = Nothing

  Set ObjFSO = Nothing

  %>

Open in new window

0
 
LVL 4

Author Comment

by:swinslow
ID: 24022529
GetData.asp
<%

    Server.ScriptTimeout = 9999

    Response.Buffer = False

    SaveToFolder = "D:\Temp\"

    TheURL = "http://infopage.cummins.com/InfoPage/Forms/SalesOrders/Export/SalesOrders.asp"

    SaveAs = "SalesOrders.tsv"

    

    Set xmlHTTP = CreateObject("MSXML2.ServerXMLHTTP")

    SaveAsFile = SaveToFolder & SaveAs

    xmlHTTP.open "GET", TheURL, false

    xmlHTTP.send()

    If xmlHttp.Status = "200" AND xmlHttp.Status <> "404" then

       Set DataStream = CreateObject("ADODB.Stream")

         DataStream.Open

         DataStream.Type = 1

         DataStream.Write xmlHTTP.ResponseBody

         DataStream.Position = 0

         DataStream.SaveToFile SaveAsFile

         DataStream.Close

       Set DataStream = Nothing

    End If

    Set xmlHTTP = Nothing
 

   Set ObjFSO = Createobject("Scripting.FileSystemObject")

   Set DataFile = ObjFSO.OpenTextFile(SaveToFolder & SaveAs)
 

   'This SHOULD read just the first line of the file

   'But it isnt

   ColumnNamesLine = DataFile.ReadLine

   Response.Write ColumnNamesLine & "<hr>"
 

   Set DataFile = Nothing

   Set ObjFSO = Nothing

 %>

Open in new window

0
 
LVL 65

Accepted Solution

by:
RobSampson earned 300 total points
ID: 24034378
Hi, this might be because of the way you're writing the carriage return in the write section.

Try changing this bit:
Response.Write chr(13) & chr(10)

to this
Response.Write vbCrLf

Regards,

Rob.
0
 
LVL 4

Author Comment

by:swinslow
ID: 24078772
I gave that a try and I still had the same result.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 300 total points
ID: 24082496
OK, this section doesn't appear to actually "create" a file:

  For Each ColumnName in Objrs.Fields
     Response.Write ColumnName.Name & chr(9)
  Next
  While Not Objrs.EOF
     'Create line feed
     Response.Write chr(13) & chr(10)
     For Each ColumnName in Objrs.Fields
        Response.Write ColumnName.value & chr(9)
     Next
  Objrs.MoveNext
  Wend
  objrs.Close



Try the below in place of that section.

Regards,

Rob.
Set objOutput = objFSO.CreateTextFile("myoutput.txt", True)

  For Each ColumnName in Objrs.Fields

     objOutput.Write ColumnName.Name & chr(9)

  Next

  While Not Objrs.EOF

     'Create line feed

     objOutput.Write vbCrLf

     strLine = ""

     For Each ColumnName in Objrs.Fields

        If strLine = "" Then

          strLine = ColumnName.value

        Else

          strLine = strLine & Chr(9) & ColumnName.value

        End If

     Next

     objOutput.Write strLine

  Objrs.MoveNext

  Wend

  objrs.Close

Open in new window

0
 
LVL 4

Author Comment

by:swinslow
ID: 24082883
You are right, it doesnt actually create a file. It is virtual. The reason I am not creating an actual physical file is that both scripts will be on different servers. The GetData.asp file will be run by the end user to get the absolute most current data and transfer it to his server (using xmlhttp). If I went with a script that created an actual file, then I would need another script to call that file and somehow schedule it (which since the website is hosted would be impossible).

But anyway.... you did give me an idea and it worked. It makes absolutley no sense at all, but in the CreateFile.asp I changed the file name from a tsv file to a txt file and it works.
0
 
LVL 4

Author Closing Comment

by:swinslow
ID: 31564507
I used partial pieces of your suggestions along with coming up with some other ideas based on your suggestions to get the final solution.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 24083066
Hmmm, tsv to txt....odd....perhaps it the way the system "expected" to read a tsv......as opposed to txt, which is just "whatever goes".

Anyway, glad you got it sorted.

Regards,

Rob.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Select distinct 25 83
How to debug this code 7 56
Scheduled IIS .Net2 AppPools recycle and SQL connection Hangs 33 91
Best way to export and then import DHCP to a new server? 6 62
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now