Hi there,
My first try with real time zip which we want to use on an asp.net site. We are currently using another component but the time from user initiating a multifile zip download to starting the download i.e. the add file/compression stage, is far too long. I'm hoping that zip on the fly will cut this time dramatically.
I've adapted the code in your help files to use a memorystream, but once downloaded the zip file contains the correct number & names of the files, but each is 0 bytes in length.
Could someone comment on the code below and point out where I could be going wrong. Assume that the source files are valid and all permissions are correct.
Xceed.Zip.ReaderWriter.Licenser.LicenseKey =
"trial licence key here"
'The target Zip archive
Using memStream As New MemoryStream()
'Create the ZipWriter object around the stream.
Dim zipWriter1 As New Xceed.Zip.ReaderWriter.ZipWriter(memStream)
'The source directory
Dim directoryInfo As New DirectoryInfo("C:\files\")
If directoryInfo.Exists Then
'Get files in the current directory and all subdirectories.
Dim files As FileInfo() = directoryInfo.GetFiles("*.*", SearchOption.TopDirectoryOnly)
For Each file As FileInfo In files
'Create ZipItemLocalHeader for current item and write to archive.
Dim zipItemLocalHeader1 As New ZipItemLocalHeader(file.Name)
zipWriter1.WriteItemLocalHeader(zipItemLocalHeader1)
Dim buffer As Byte() = New Byte(1023) {}
Dim read As Integer = 0
Using fs As FileStream = file.OpenRead()
'Read the current item's data
Do While (read = fs.Read(buffer, 0, buffer.Length)) <> 0
'Write the current item's data to the Zip archive
zipWriter1.WriteItemData(buffer, 0, read)
Loop
End Using
Next file
'Close the Zip archive. Writes the archive's central header.
zipWriter1.CloseZipFile()
'Convert the memory stream to an array of bytes.
Dim byteArray As Byte() = memStream.ToArray()
Response.Clear()
Response.ContentType =
"application/x-zip-compressed"
Response.AddHeader(
"Content-Disposition", "attachment;filename=my_archive.zip")
Response.AppendHeader(
"Content-Length", byteArray.Length.ToString())
Response.BinaryWrite(byteArray)
Response.End()
End If
End Using