I have a grid view/telerik rad grid with check box in each row where user can choose whatever documents do they need to download and there is normal asp.net button outside Grid which can be used to download all selected files from azure blobs to user's computer.I used ICSharpCode.SharpZipLib.Zip from nuget package,it did not work.No error ,but not downloading any files.Any solutions? .
Imports ICSharpCode.SharpZipLib.Zip
Protected Sub downloadbutton_Click(sender As Object, e As EventArgs) Handles downloadbutton.Click
Response.AddHeader("Content-Disposition", "attachment; filename=" + "myfilezip" + ".zip")
Response.ContentType = "application/zip"
Using zipStream As ZipOutputStream = New ZipOutputStream(Response.OutputStream)
For Each item As Telerik.Web.UI.GridDataItem In grid.Items
If CType(item.FindControl("myCheckBox"), CheckBox).Checked Then
Dim blockBlob As CloudBlockBlob = GetStorageAccountDetails.GetBlockBlobReference(""container info and file path)
Dim sr as stream= blockBlob.OpenRead()
Dim ms As System.IO.MemoryStream = New IO.MemoryStream()
sr.CopyTo(ms)
Dim buffer As Byte() = ms.ToArray()
Dim fileEntry = New ZipEntry(fileName) With {
.Size = buffer.Length()
}
zipStream.PutNextEntry(fileEntry)
zipStream.Write(buffer, 0, buffer.Length)
End If
Next
zipStream.Flush()
zipStream.Close()
end sub
I used DotNetZip library, downloaded via Nuget package manager and it worked well.
Response.Clear()
Response.BufferOutput = False
Dim archiveName As String = "myfile.zip"
Response.ContentType = "application/zip"
Response.AddHeader("content-disposition", "filename=" + archiveName)
Dim i as integer=1
Using zipDownload1 As Ionic.Zip.ZipFile = New Ionic.Zip.ZipFile()
For Each item As Telerik.Web.UI.GridDataItem In Grid.Items
If CType(item.FindControl("mycheckbox"), CheckBox).Checked Then
Dim blockBlob As CloudBlockBlob = GetStorageAccountDetails.GetBlockBlobReference(""container info and file path)
Dim sr as stream= blockBlob.OpenRead()
Dim ms As System.IO.MemoryStream = New IO.MemoryStream()
sr.CopyTo(ms)
Dim buffer As Byte() = ms.ToArray()
zipDownload1.AddEntry("fileName"+i.tostring(), buffer)
i=i+1
End If
Next
zipDownload1.Save(Response.OutputStream)
Response.Close()
End Using