DotNetZip error sending zip file to browser

Apr 17, 2012 at 9:38 PM

Hi.  It's my first time using DotNetZip.  Seems like a great tool, but I'm banging my head against the wall trying to figure this out.  I'm trying to enable the downloading of files checked on a vb.net webpage.  It seems to fail when I hit the line "zip.Save(Response.OutputStream)".

Here is the error message:

Message: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near 'PK'.

And here is the relevant portion of code I'm using to attempt this:

            Dim downloadFileName = "Files.zip"
            Response.Clear()
            Response.AddHeader("content-disposition", "filename=" & downloadFileName)
            Response.ContentType = "application/zip"

            Dim connStr As String
            connStr = ConfigurationManager.ConnectionStrings("accessConnStr").ConnectionString
            Dim Conn As New OleDbConnection(connStr)

            Conn.Open()

            Dim cmd As New OleDbCommand("select * from filesUpload where id in(" & strID & ")", Conn)

            Dim rdr As OleDbDataReader
            rdr = cmd.ExecuteReader()

            Using zip As New ZipFile()

                Dim fileName = ""
                While rdr.Read
                    fileName = rdr("fileName")
                    zip.AddFile("c:/inetpub/wwwroot/gat/docs/" & projID & "/" & fileName, "Requested Files")
                End While
	       rdr.Close()
	       Conn.Close()
	       Conn.Dispose()
                zip.Save(Response.OutputStream)

            End Using

            Response.End()

Any ideas as to what I'm doing wrong and causing this error are greatly appreciated. Thanks.
Jim
Apr 18, 2012 at 4:27 AM

Problem solved.  The button I used to trigger the download was within an UpdatePanel which conflicted with the output stream.  Moved the button outside of the UpdatePanel and bingo, it worked.