views:

52

answers:

2

Hi,

I'm trying to download remote file using C# (ASP.NET). The problem is when I browse to the file download URL - it downloads perfectly. When I try the WebClient.DownloadData(url) I get "no data to show" response.

If I browse using the built-in VS2010 browser I still get this "error" message.

The file link is: http://www.tase.co.il/TASE/Pages/Export.aspx?sn=he-IL_ds&enumTblType=AllSecurities&Columns=he-IL_Columns&Titles=he-IL_Titles&TblId=0&ExportType=3 (CSV file)

How can the file be downloaded? any ideas?

Many Thanks

A: 

This isn't a download problem on your side, that page is referencing something, probably from session...so you would need to login to the site, get a session, basically go through whatever steps you normally would in route to getting the file so it's generated correctly/available.

If I had to take a guess, I'm thinking they do the export to the file system when you ask for it, so it's a temp file somewhere...not something you can just grab, so unless you went through the step that created it (doesn't seem this Export.aspx page does it), it won't be there, and their error message for this is "No data to show".

There's also the possibility they're explicitly blocking you to prevent any kind of bots/leeching from happening...basically preventing exactly what you're trying to do.

Nick Craver
But that's strange - if you try to browse to that page, without authentication of any kind, you get to download the file.So my guess there are no sessions there - just some kind of blockage?
Roman
@Roman - There might be, blocking by referrer to prevent leeching I'd guess, it's a pretty common hot-linking counter-measure.
Nick Craver
@Nick - If it was so, wouldn't they block direct-browsing download? If I'd browse directly to the link - they'd have no referrer and thus would block me. wouldn't they?
Roman
@Roman - it *is* blocked here, are you sure you don't have a session in whatever browser you're using?
Nick Craver
A: 

Many sites will block downloads based on the Referer or User-Agent header.

  1. Watch a "working" download with Fiddler
  2. Watch your code's download with Fiddler
  3. Compare the two requests
  4. Update your request to match the "working" case.
EricLaw -MSFT-