Capturing a csv file from a website

Is there a way to capture the contents of a .csv file that is being sent from a web site? What I am trying to do is get the file and read it, line by line, into a string array without making the user save the file first. I want to intercept it before the HTMLViewer puts up the save dialog.

This is for a Windows desktop app so a web solution won’t work.

Thanks,
Dale

Yup.
If you request it using a socket, the response you get is just a string.
The string is what you would have got if you had a local file and read it all into memory at once.

Is the problem that people click on the link in an HTMLViewer?

Check the extension of the file in the CancelLoad event.
If it is CSV, download it using an HTTPSocket, and return TRUE in the event to cancel the processing by HTMLViewer

Hmmm. That sounds like it might be the way to go.

The scenario is that the contents being retrieved change daily and my app needs to be able to update [semi]automatically. I don’t want the user to have to deal with, or even have to know about the CSV file.

I’ll have to give using sockets a try. Thanks.

Provided that the URL of the CSV file stays the same while its contents change, you could entirely skip the HTMLViewer and just use a Socket instead.

Use http://documentation.xojo.com/index.php/HTTPSocket.GetHeaders to get the date modified of the CSV file before downloading. That way you can decide whether it is worth spending the bandwidth to download the actual file. Just cache the date/time of the last file downloaded so you know if you already grabbed that file.

And if the csv file is a bit too weight, you can save it in the TemporaryItems (SpecialFolder.Temporary) folder and do the file scan from there…

In fact, the URL does remain constant so I did yank out the HTMLViewer and am just using the socket. The contents of the csv file may change from moment to moment but, after the initial read, I leave it to the user to refresh the data when/if needed. Of course, the csv file will get read every time the app opens or the user makes a change to other data in the window. The csv file isn’t large so it isn’t much of a load to just grab the data.

Thanks to all for the help. I have it working in Classic so now I’m going to try it in Xojo.Framework (part of my learning experience!)

Ok, so I’m trying to move this reading a CSV file from a URL from Classic to new Framework. In the classic framework the HTTPSocket.Get can be made synchronous by adding the optional timeout parameter. I don’t see a way to achieve this in the new framework. My application needs to rapidly read several CSV files (generally less than 10, each with less than 64 characters) so reading them synchronously works fine in the old framework.

In the new framework, how do I tell the socket that it is done and it can process the next “GET”? I can’t simply put it in a loop because I get an “UnsupportedOperationException: A request is already in progress.” error the second time I send the GET request.

I know I’m missing something but I don’t know what. (Duh! If I knew what, I wouldn’t be missing it! )

Again, this is a Windows Desktop app.

Thanks,
Dale

Oh boy does that sound familiar. https://forum.xojo.com/28387-reusing-xojo-net-httpsocket/ That post explains what’s going on (you may think your request is done but it isn’t.) It also discusses some approaches such as creating a new socket for each request or using a timer to send a new request once the previous one is actually finished.

Zonkers, Scott, that redirect was exactly what I needed. Thanks.