how do I download a large file (via HTTP) in .NET
        Posted  
        
            by nickcartwright
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by nickcartwright
        
        
        
        Published on 2009-07-03T09:19:40Z
        Indexed on 
            2010/03/19
            19:11 UTC
        
        
        Read the original article
        Hit count: 224
        
I need to download a LARGE file (2GB) over HTTP in a C# console app. Problem is, after about 1.2GB, the app runs out of memory.
Here's the code I'm using:
WebClient request = new WebClient();
request.Credentials = new NetworkCredential(username, password);
byte[] fileData = request.DownloadData(baseURL + fName);
As you can see... I'm reading the file directly into memory. I'm pretty sure I could solve this if I were to read the data back from HTTP in chunks and write it to a file on disk.
Does anyone know how I could do this?
© Stack Overflow or respective owner