I am making a call to a httprequest which returns a pdf file in the responsestream. This works well for smaller pdf's, but not the file is up around 25-30MB, it is returning an out of memory exception.
MemoryStream memStream = new MemoryStream();
byte[] buffer = new byte[2048];
int bytesRead = 0;
do
{
bytesRead = _ResponseStream.Read(buffer, 0, buffer.Length);
memStream.Write(buffer, 0, bytesRead);
} while (bytesRead != 0);
_ResponseStream.Close();
_ResponseStream.Dispose();
_ResponseStream = null;
if (memStream.Length > 0)
return memStream;
else return null;
Machine specs are Quad Core 3.0GZ, 4GB RAM (Physical Box). It is possible that the PDF could reach sizes of 60MB. Multiple users can download at thte same time. How would this effect it? Would it be better to take the response stream straight to a FileStream? Is there a best practice way of doing this?