【发布时间】:2015-09-04 20:59:55
【问题描述】:
我已经构建了一个包含多个条目的 DotNetZip ZipFile。我想将它转换为字节数组,以便我可以使用下面的下载结构下载它。
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()
我知道有一个 ZipFile 方法可以解决这个问题:
wrkZip.Save(context.Response.OutputStream)
但是,我在使用它时遇到了一个困难的错误,如下所述:
DotNetZip download works in one site, not another
所以我正在寻找一个短期的解决方法。关于该错误的简短故事是 ZipFile 可以正常写入磁盘,并且可以在非常相似的网站上正常下载;它只是在我现在需要它的情况下不起作用。
那么,如何将 DotNetZip ZipFile 转换为字节数组?我查看了其他答案,但是他们没有描述转换整个加载的 ZipFile 的这种特殊情况。
【问题讨论】: