How to download a file? Need a .NET version of URLDownloadToFile

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I know, this question was posted few times already,
but I failed to find a definitive answer.

A usual answer is to use System.Net.WebClient.DownloadFile,
but it does not work for me because:
- I need the HTTP request to be identical (or very close)
to what IE normally sends (this includes cookies and other headers).
URLDownloadToFile is good at that, but WebClient is not.

- I need to be notified about progress status, in particular about
redirection and Mime type. URLDownloadToFile gives a very
detailed progress and status, but WebClient only gives the
number of bytes downloaded.

Other people suggest using HttpWebRequest directly, set headers manually,
initialize CookieCollection, etc, etc, etc. But all of this is such a pain!

I wonder whether even the later version of .NET still does not have
a convenient API for file download.

Thank you
John
 
Hi,
I know, this question was posted few times already,
but I failed to find a definitive answer.

A usual answer is to use System.Net.WebClient.DownloadFile,
but it does not work for me because:
- I need the HTTP request to be identical (or very close)
to what IE normally sends (this includes cookies and other headers).
URLDownloadToFile is good at that, but WebClient is not.

- I need to be notified about progress status, in particular about
redirection and Mime type. URLDownloadToFile gives a very
detailed progress and status, but WebClient only gives the
number of bytes downloaded.

Other people suggest using HttpWebRequest directly, set headers manually,
initialize CookieCollection, etc, etc, etc. But all of this is such a
pain!

I wonder whether even the later version of .NET still does not have
a convenient API for file download.

Create DllImport attribute on URLDownloadToFile
and implement the callback function. Let us know if you succeed.
The callback 'pointer' is *especially* meant for what you want.


However, you since can use a binary download on HttpWebRequest and download
in blocks. First you should read the Content-Length
then you can read in blocks of say 4096 bytes use the binary stream
(GetResponseStream()).
 
Create DllImport attribute on URLDownloadToFile
and implement the callback function. Let us know if you succeed.
The callback 'pointer' is *especially* meant for what you want.

No luck so far.

The last argument of URLDownloadToFile is IBindStatusCallback interface.
I cannot find any type library, which defines IBindStatusCallback,
therefore, I cannot simply import it to C# code.

I guess (but not completely sure) that there must be a way to redeclare
this interface (and several referenced interfaces and data structures)
entirely in C#, but this appears to be such a pain!

I guess the simplest solution would be to write a completely separate
unmanaged DLL, which will perform download.

Any other options?

John
 
Back
Top