Simon Mourier's Avatar
Simon Mourier's blog (1807 answers on StackOverflow) about Microsoft technologies C#, C/C++, .NET, WinRT, WinUI3, AOT, P/Invoke, COM, Interop, DirectX, Direct2D, Windows, ...
  • 🔎︎ Search
  • Categories
  • Archives
  • About Me
  • asp.net
  • c#
  • web

Download large file in small chunks in C#

Nov 26, 2012 See the question and my original answer on StackOverflow

You should check how much was read before write, something like this (and you don't need to remember the offset to seek, the seek is automatic when you write):

int read;
do
{
    read = responseStream.Read(bytesInStream, 0, (int)bytesInStream.Length);
    if (read > 0)
        fileStream.Write(bytesInStream, 0, read);
}
while(read > 0);
  • SmoBlog © 2010-2026 Simon Mourier. All rights reserved.
  • Privacy & Terms