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

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
 
E

Egbert Nierop \(MVP for IIS\)

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()).
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top