Jun 18, 2015 at 11:13 PM
Edited Jun 19, 2015 at 6:12 PM
I thought this was a problem with ZipFile.Save(to page context).
However, I rewrote the function below to convert the ZipFile to memorystream and then to binary array, and then download the binary array, and it gives the same error. The ZipFile saves to disk just fine, so I don't think it's the file content. Summary
is that this is probably not a ZipFile issue, so doesn't really belong in this forum any more.
The code below works fine in a test site but fails in the main site (both are dev sites on the same machine).
The code below is set up to have a switch to write to disk or not.
A) When it is set to write to disk, the disk write looks fine; well formed zip, opens fine, content is as expected. However, when it then hits this statement:
it jumps to the catch with this error:
"Cannot read that as a Zip file".
B) when it is set to skip the write to disk, there is no error, but also no action, and the page goes "dead", i.e. local js still works but callbacks don't. It recovers with F5 on the browser.
Again, the exact same code including this:
works fine on the test site.
I have a more extensive write up here:
Where I describe how I replicated the exact same download data in both the test and main sites.
However it seems to narrow down to the "zip.save to download stream" statement, and it's a mystery why it works in the test site but not the main site.
Any suggestions on further diagnostics or fixes would be appreciated.
Public Sub ZipAndDownloadMemoryStreams(ByVal context As HttpContext) _
Dim rtn As String = ""
Dim wrkAr As ArrayList
wrkAr = SC.ContentArrayForDownLoad
If wrkAr.Count = 0 Then
Dim wrkStop As Integer = 0
Dim wrkFS As ZipDownloadContentPair
Using wrkZip As New ZipFile
'----- create zip, add memory stream----------
For n As Integer = 0 To wrkAr.Count - 1
wrkFS = wrkAr(n)
context.Response.ContentType = "application/force-download"
"attachment; filename=" & "_AMPTK_Export.zip")
'---- save context (initiate download)-----
Dim wrkFilePath As String = ""
If 1 = 1 Then
wrkFilePath = "D:\XYZ\test.zip"
Catch ex As Exception
Dim exmsg As String = ex.Message
Dim wrkStop As String = ""