我已经构建了一个包含多个条目的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()
Run Code Online (Sandbox Code Playgroud)
我认识到有一个ZipFile方法:
wrkZip.Save(context.Response.OutputStream)
Run Code Online (Sandbox Code Playgroud)
但是,我在使用它时遇到了一个难题,如下所述:
所以我正在寻找一个短期的解决方法.关于该漏洞的简短故事是ZipFile写入磁盘,并在一个非常相似的网站上下载; 它只是在我现在需要它的情况下不起作用.
那么,如何将DotNetZip ZipFile转换为字节数组呢?我查看了其他答案,但是他们没有描述转换整个加载的ZipFile的特殊情况.
使用a MemoryStream将内容转换为字节数组:
Dim ms as New MemoryStream
wrkZip.Save(ms)
wrkBytes = ms.ToArray()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2720 次 |
| 最近记录: |