-1

I have five file in temp folder for download that file. my aim is download all file but now it download first file.

I try this code for download all file

Dim strSrcFolder As String = Server.MapPath("~/TempFiles/senthil/PDF/") Dim dinfo As New DirectoryInfo(strSrcFolder) For Each finfo As FileInfo In dinfo.GetFiles() Dim stringFName As String = finfo.Name

        Response.ContentType = "application/pdf"
        Response.AppendHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(stringFName, System.Text.Encoding.UTF8))
        Response.TransmitFile(Server.MapPath("~\TempFiles\senthil\PDF\" + stringFName))
        Response.End()
    Next
Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
senthil
  • 21
  • 3
  • 3
    Possible duplicate of [How to Download Multiple Files using ASP.NET?](https://stackoverflow.com/questions/22413679/how-to-download-multiple-files-using-asp-net) – CodeCaster Sep 04 '18 at 10:39
  • 2
    HTTP itself doesn't allow multiple files in the response. As the duplicate question shows, you can zip multiple files and return the zipped file – Panagiotis Kanavos Sep 04 '18 at 10:46

1 Answers1

-1
 Dim i As Integer
    Dim TxtLocalSysName As String = Request.UserHostName
    Dim readStream As FileStream
    Dim writeStream As FileStream
    Try
        For i = 0 To lstdownload.Items.Count - 1
            Dim filePath As String = Me.Label5.Text + "\" + lstdownload.Items(i).Text
            Dim targetFile As System.IO.FileInfo = New System.IO.FileInfo(filePath)
            readStream = New FileStream(filePath, FileMode.Open)
            Dim length As Integer = Convert.ToInt32(readStream.Length)
            'This is the buffer.
            Dim byteFile() As Byte = New Byte(length) {}
            readStream.Read(byteFile, 0, length)
            readStream.Close()
            Dim localPath As String = "\\" & TxtLocalSysName & "\c$\downloads"
            If Not Directory.Exists(localPath) Then
                Directory.CreateDirectory(localPath)
            End If
            writeStream = New FileStream(localPath & "\" & targetFile.Name, FileMode.Create)
            writeStream.Write(byteFile, 0, length)
            writeStream.Close()
        Next i
    Catch ex As Exception
        Console.WriteLine("The process failed: {0}", ex.ToString())
    Finally
        readStream.Close()
        readStream.Dispose()
        writeStream.Close()
        writeStream.Dispose()

    End Try
nisha
  • 21
  • 2
  • Hi sir, thanks for reply my website i put server side so all zip file download in server side.i need the all zip file in client side using above code pls reply soon ASPA – senthil Sep 18 '18 at 05:29