Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2006

Tip: Looking for answers? Try searching our database.

Advice on Handling Large File Download via HTTP

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark Olbert - 14 Mar 2006 23:38 GMT
I'm writing a C# app which downloads large files via http from a server. These files are often in excess of a gigabyte.

I am trying to figure out the best way to download these kinds of large files in .NET. While I've successefully downloaded test
files using WebClient, I don't think that's going to be a viable final solution because I need to be able process the data stream
before writing it to the local disk (basically, I need to strip off certain bytes). I haven't found a WebClient method which allows
me to "intercept" the downloaded data stream to process it.

I've played around with WebRequest and WebResponse, but am running into a situation where no more than the first 256K bytes of data
is readable. In other words, if I do something like this (pseudo code):

WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();

while( not enough bytes read yet )
{
    stream.Read(buffer...)
    localFileStream.Write(buffer...)
}

only the first 256K bytes are read from the stream. After that, the stream.Read() has a return value of 0.

So...what advice do folks have on how I should move forward?

- Mark
Mark Olbert - 15 Mar 2006 01:25 GMT
One correction: the "256K byte limit" problem was self-inflicted (some old logic I forgot to remove).

But I'm still interested in advice on downloading large files via http.

- Mark
"Yuan Ren[MSFT]" - 16 Mar 2006 07:35 GMT
Hi Mark,

Thanks for posting!

I'm glad to hear the issue has been resolved:

In addition, there are many samples from third party demonstrate how to
approach this. I suggest you follow two articles below:
"Cool C# File Downloader":
http://www.codeproject.com/csharp/CoolDownloader.asp

"Threaded WebDownload class with Progress Call-backs":
http://www.codeproject.com/csharp/webdownload.asp

They are appropriated at the current stage. Thanks for your understanding!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support
Joerg Jooss - 15 Mar 2006 21:35 GMT
Thus wrote Mark,

> I'm writing a C# app which downloads large files via http from a
> server. These files are often in excess of a gigabyte.
[quoted text clipped - 9 lines]
>
> me to "intercept" the downloaded data stream to process it.

When you use WebClient.OpenStream(), you can process the reponse stream directly.

But for GB sized download, I'd rather think about something more advanced
than plain HTTP, like BITS for example.

Cheers,
Signature

Joerg Jooss
news-reply@joergjooss.d


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.