swinslow
asked on
Readline is reading entire text document
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.
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.
ASKER
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
%>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I gave that a try and I still had the same result.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
ASKER
I used partial pieces of your suggestions along with coming up with some other ideas based on your suggestions to get the final solution.
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.
Anyway, glad you got it sorted.
Regards,
Rob.
ASKER
Open in new window