Download Multiple Files in a Single Archive with RadZipLibrary

1 posts, 0 answers
  1. Eyup
    Eyup avatar
    6 posts
    Member since:
    Oct 2012

    Posted 22 Oct Link to this post

    Requirements


    Telerik Product and Version

    3.5+

    Supported Browsers and Platforms

    All browsers supported by Telerik UI for ASP .NET AJAX

    Programming language

    VB

    PROJECT DESCRIPTION

    This sample demonstrates how to download multiple files from various formats within a single .zip archive by making avail of the Telerik's RadZipLibrary control. In order to use this zip library, you can include the required assemblies as explained in this article:
    Telerik ZIP Library 

    You can find the original more advanced version of this implementation in the following live demo:
    RadZipLibrary Overview

    Zip Library Archive

    Code-behind logic:

    Protected Sub RadButton1_Click(sender As Object, e As EventArgs)
            Dim memStream As New MemoryStream()
     
            Using archive As New ZipArchive(memStream, ZipArchiveMode.Create, True, Nothing)
                For Each docFile As String In Directory.GetFiles(HttpContext.Current.Server.MapPath("~/Files"))
                    Using entry As ZipArchiveEntry = archive.CreateEntry(Path.GetFileName(docFile))
                        Using writer As New BinaryWriter(entry.Open())
                            writer.Write(File.ReadAllBytes(docFile))
                        End Using
                    End Using
                Next
            End Using
     
            SendZipToClient(memStream)
        End Sub
     
        Private Sub SendZipToClient(memStream As MemoryStream)
            memStream.Seek(0, SeekOrigin.Begin)
     
            If memStream IsNot Nothing AndAlso memStream.Length > 0 Then
                Response.Clear()
                Response.AddHeader("content-disposition", "attachment; filename=files.zip")
                Response.ContentType = "application/zip"
                Response.BinaryWrite(memStream.ToArray())
                Response.[End]()
            End If
        End Sub


Back to Top