Convert DotNetZip ZipFile to Byte Array
I created a DotNetZip ZipFile with multiple entries. I would like to convert it to a byte array in order to load it using the load construct below.
Using wrkZip As New ZipFile
'----- create zip, add memory stream----------
For n As Integer = 0 To wrkAr.Count - 1
wrkFS = wrkAr(n)
wrkZip.AddEntry(wrkFS.FileName, wrkFS.ContentStream)
Next
dim wrkBytes() as Byte
dim wrkFileName as string = "Test.txt"
===> wrkBytes = ConvertToByteArray(wrkZip) <====
context.Response.Clear()
context.Response.ContentType = "application/force-download"
context.Response.AddHeader("content-disposition", "attachment; filename=" & wrkFileName)
context.Response.BinaryWrite(wrkBytes)
wrkBytesInStream = Nothing
context.Response.End()
I understand there is a ZipFile method for this:
wrkZip.Save(context.Response.OutputStream)
However, I have a tricky error in using this described here:
Downloading DotNetZip works on one site and not another
so I am looking for a short term workaround. A short history of the error is that ZipFile writes to disk in order and loads on a very similar website; it just doesn't work if I need it right now.
So how do I convert DotNetZip ZipFile to byte array? I have looked at other answers however they do not describe this specific case of converting an integer loaded ZipFile.
source to share
Use MemoryStream
to get content into byte array:
Dim ms as New MemoryStream wrkZip.Save(ms) wrkBytes = ms.ToArray()
source to share