0

Hi there,
I have a database which contains the paths of different files, what I want to do is to store the paths in an array to create an array of paths then download these files with one click.

How to do that?
please help

2
Contributors
6
Replies
16
Views
4 Years
Discussion Span
Last Post by pritaeas
0

how to download multiple files with one click, I have the paths in an array

0

i did that but got nothing

this is the code

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim i As Integer = 0
            Dim pp() As String = {"F:\New folder (2)\1. pdf", "F:\New folder (2)\2.txt", "F:\New folder (2)\3.docx"}
            Dim files As New List(Of ListItem)()
            For Each filePath As String In pp
                files.Add(New ListItem(pp(i)))
                i = i + 1
            Next
            GridView1.DataSource = files
            GridView1.DataBind()
        End If
    End Sub

    Protected Sub btnDownload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDownload.Click
        Using zip As New ZipFile()
            zip.AlternateEncodingUsage = ZipOption.AsNecessary
            zip.AddDirectoryByName("files")
            For Each row As GridViewRow In GridView1.Rows
                Dim filePath As String = TryCast(row.FindControl("lblFilePath"), Label).Text
                zip.AddFile(filePath, "files")
            Next
            Response.Clear()
            Response.BufferOutput = False
            Dim zipName As String = [String].Format("Zip_{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"))
            Response.ContentType = "application/zip"
            Response.AddHeader("content-disposition", "attachment; filename=" + zipName)
            zip.Save(Response.OutputStream)
            Response.[End]()
        End Using
    End Sub
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.