Search code examples
c#asp.netdownloadhttpcontext

How to perform a download instantly with ASP.NET C#?


We have a rather large amount of data to be downloaded.

Currently our system just outputs the stream (we do not use files)

Code:

         HttpContext.Current.Response.AppendHeader("content-disposition", String.Format("attachment; filename={0}", filename));
            HttpContext.Current.Response.BinaryWrite(ms.ToArray());

            HttpContext.Current.Response.End();

However, it is using an extensive amount of memory on the server, waiting for the file to download.. I'd like to make it so it starts to download immediately rather than waiting... How can I do this?


Solution

  • Try setting this:

    HttpContext.Current.Response.BufferOutput = false;