The following code works well with small files, like 100MB, but it throws a System.OutOfMemoryException
for bigger files, like 400MB. I'm using the NotNetZip as dll to get file as zip.
This is my code:
string pathGetDoc = pathDocs + "\\" + informe.NickName + "\\" + getMesActual() + "\\" + informe.Name;
string fileName = informe.Name;
System.Net.WebClient wc = new System.Net.WebClient();
wc.OpenRead(pathGetDoc);
int bytes_total = Convert.ToInt32(wc.ResponseHeaders["Content-Length"].ToString());
if(bytes_total >= 100000000)
{
using (ZipFile zip = new ZipFile())
{
zip.AddFile(pathGetDoc, fileName);
zip.CompressionMethod = CompressionMethod.BZip2;
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
using (MemoryStream memoryStream = new MemoryStream())
{
zip.Save(memoryStream);
return File(memoryStream.ToArray(), "application/zip", "z.zip");
}
}
}
As you can see, I have a IF to check the size of the file, this work good but when the process goes to save .zip file, I have the error System.OutOfMemoryException