我已经构建了一个包含多个条目的 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 的特殊情况。
最佳答案
使用 MemoryStream
将内容放入字节数组中:
Dim ms as New MemoryStream
wrkZip.Save(ms)
wrkBytes = ms.ToArray()
关于vb.net - 将 DotNetZip ZipFile 转换为字节数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30928625/