I am using asp.net mvc application with VB.net and I am trying to zip files and stream them back to the user to download.
Here is what I am doing
Public Function DownloadFiles(attachmentsSelected As String) As ActionResult
Dim obj As FileDownloads = New FileDownloads()
''get file list of files to download
Dim filesCol = obj.GetFile(attachmentsSelected).ToList()
Using memoryStream = New MemoryStream()
Using ziparchive = New ZipArchive(memoryStream, ZipArchiveMode.Create, True)
For i As Integer = 0 To filesCol.Count - 1
//get the error here ziparchive.CreateEntryFromFile(filesCol(i).FilePath + "\" + filesCol(i).FileName, filesCol(i).FileName, CompressionLevel.Optimal)
Return File(memoryStream.ToArray(), "application/zip", "Attachments.zip")
The issue with this code is when I am trying to download large file ...let's say 500mb I get an exception.
"Exception of type 'System.OutOfMemoryExcepti
on' was thrown."
Any idea how can I fix this issue.