Downloading DotNetZip works on one site and not another

EDIT - RESOLVED: The difference was that in the "main" case the download was initiated using a callback loop, while in the "test" case it was initiated using the server side button click function. My guess is that the load request and the callback loop were interfering with each other by both stopping the load and rendering the page inactive (as described below). When I reprogrammed the download on the main page to start with a submit instead of a callback, it initiated the download.

It's in VS2013 Ultimate, Win7Pro, VB.Net, websites (not projects), IISExpress.

I built a test site to develop functionality for creating OpenXML PPTX and XLSX mass storage devices, and zipping and downloading them using DotNetZip. Got this to work fine. Then I merged all this code into my "main" site. Both sites are on the same machine; I can run the test site and the main site at the same time. Processing the main site is a little more difficult, but only in terms of accessing and downloading more files.

However, the Zip and Download function (below) works fine on the test site, but the same code does not work on the main site (with the test site up and running).

There is a bug here (see below) around the Zip.Save function where the download takes place but no error appears.

Same general behavior in Chrome, Firefox and IE11.

One feature that can be a clue is that if the main site fails to load, the server-side functionality "crashes". Local JS functions work, but the application doesn't respond to callbacks. When I do F5 in the browser it works again.

I have updated the DotNetZip package on the main site. The Zip object works fine because it generates an error when file names are duplicated.

I thought it might be the download function as written, however it works on the test site. Also, another part of the main site does an unloaded memory stream load (included as the second block of code below) and that works great.

I thought it might be data. So I blocked the main site from accessing, converting to memystream, and downloading the same file that is accessed and uploaded on the test site. However, loading the main site doesn't work.

When I compare the clock values ​​in the Zip object across the two sites, they look the same. The length of the wrkFS.ContentStream file is the same in both cases. The file names are different, however they are: Test_2EFVG1THK5.xlsx (main) 6-18_12-46-28_0.xlsx (test) which are also legitimate file names.

EDIT: I saved the zip file to disk from the main program, instead of downloading it using this:

                wrkFilePath = "D:\filepath\test.zip"
                wrkZip.Save(wrkFilePath)

      

And everything worked out great. So perhaps isolates the issue to this statement

            wrkZip.Save(context.Response.OutputStream)

      

EDIT: Based on the help I got here:

Convert DotNetZip ZipFile to Byte Array

I used this construction:

Dim ms as New MemoryStream
wrkZip.Save(ms)
wrkBytes = ms.ToArray()
context.Response.BinaryWrite(wrkByteAr)

      

to bypass ZipFile.Save (in context) and that didn't work either; no loading, no error message, and the page is down. However, at least now I can assume that this is not a problem with ZipFile.Save.

At the moment, I have no way of diagnosing the problem.

Any suggestions would be appreciated.

Here is the code that works on the test site, but not on the main site.

    Public Sub ZipAndDownloadMemoryStreams(ByVal context As HttpContext) _
Implements IHttpHandler.ProcessRequest
    Dim rtn As String = ""

    Try
        Dim wrkAr As ArrayList
        wrkAr = SC.ContentArrayForDownLoad
        If wrkAr.Count = 0 Then
            Dim wrkStop As Integer = 0
            Exit Sub
        End If

        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)
                wrkZip.AddEntry(wrkFS.FileName, wrkFS.ContentStream)
            Next

            context.Response.Clear()
            context.Response.ContentType = "application/force-download"
            context.Response.AddHeader( _
                "content-disposition", _
                "attachment; filename=" & "_XYZ_Export.zip")
            '---- save context (initiate download)-----
            wrkZip.Save(context.Response.OutputStream)
            wrkZip.Dispose()

        End Using

    Catch ex As Exception
        Dim exmsg As String = ex.Message
        Dim wrkStop As String = ""
    End Try
End Sub

      

Below is a non-zip download function that works great on the main site. It might be possible to convert the Zip content to a byte array and try loading that path, however I'm not sure how that would work.

(SEE EDIT NOTE ABOVE --- I have implemented the version below, i.e. try to load a byte array instead of direct ZipFile.Save (), however that didn't work: still doesn't load and still gives no error message)

Public Sub DownloadEncryptedMemoryStream(ByVal context As HttpContext) _
    Implements IHttpHandler.ProcessRequest

    Dim wrkMemoryStream As New System.IO.MemoryStream()

    wrkMemoryStream = SC.ContentForDownload

    Dim wrkFileName As String = SC.ExportEncryptedFileName

    wrkMemoryStream.Position = 0
    Dim wrkBytesInStream As Byte() = New Byte(wrkMemoryStream.Length - 1) {}
    wrkMemoryStream.Read(wrkBytesInStream, 0, CInt(wrkMemoryStream.Length))

    Dim wrkStr As String = ""
    wrkStr = Encoding.UTF8.GetString(wrkMemoryStream.ToArray())


    wrkMemoryStream.Close()
    context.Response.Clear()
    context.Response.ContentType = "application/force-download"
    context.Response.AddHeader("content-disposition", "attachment; filename=" & wrkFileName)
    context.Response.BinaryWrite(wrkBytesInStream)
    wrkBytesInStream = Nothing
    context.Response.End()

      

0


source to share


1 answer


(Note now at the top of the question): The difference was that in the "main" case the download was initiated with a callback loop, while in the "test" case it was initiated with a server side button click. My guess is that the load request and the callback loop were interfering with each other by both stopping the load and rendering the page inactive (as described below). When I reprogrammed the download on the main page to start with a submit instead of a callback, it initiated the download.



0


source







All Articles