473,396 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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


Nov 19 '05 #1
2 2257

<John> wrote in message news:85********************@speakeasy.net...
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()).

Nov 19 '05 #2
> 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
Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Brandon Walters | last post by:
I wrote a file download module for my website. The reason for the file download module is that my website downloads work on a credit based system. So I need to keep track of and limit daily...
1
by: Dave | last post by:
Hi Everyone, I was wondering if anyone has ever successfully used SA-FileUp's download feature. I am being forced to change from "ASPSmartUpload" as the server I am moving everything to is...
3
by: Brent Billups | last post by:
I am trying to download files from one website to another for purposes of caching. In trying to do this, I created a VB dll component (using VB6), that used URLDownloadToFile, to allow me to...
0
by: Steeden Macdonalds via .NET 247 | last post by:
Hi, Can anyone help me with this, I'm trying to use URLDownloadToFile in VB.NET but it doesn't seem to work. I've tried using DownloaFile in System.Web.Webclient but this doesn't suit my purpose....
5
by: FERNANDEZ Emmanuel | last post by:
Hello, Are there any solutions (in C ANSI) for downloading internet files ? Some functions exist (URLDownloadToFile(...) or URLDownloadToCacheFile(...) for Windows) but they aren't ANSI. ...
1
by: theburnetts | last post by:
I am building an ASP.NET application that has a requirement that the user should be able to download all of the data that they have input into the system and save it to a file on their local PC. ...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.