How to download multiples files with Webforms vb.net inside a loop

JERONIMO Edevaldo 40 Reputation points
2023-10-27T13:31:40.5066667+00:00

I need to download the files using webforms with only one button click but only the first file are downloaded.

How can i do it?

See my code vb code.


StrSql = "Select * from TblOS_Anexo"
StrSql = StrSql & " WHERE TblOS_Anexo.IdOS = " & Me.IdOS.Text
StrSql = StrSql & " ORDER By TblOS_Anexo.Seq_Anexo "

Try
    Dim TblOS_Anexo As SqlClient.SqlDataReader = Classes.Class_CriaData_SqlServer.CriaDataReader(Application("Bd_ConnectionString"), StrSql)

    If TblOS_Anexo.HasRows Then
        Do While TblOS_Anexo.Read
            Anexo = TblOS_Anexo("Anexo")
            StrPath = MapPath("~/Anexo_OS/") & Anexo
            TblOS_Anexo("Anexo"))
            If File.Exists(StrPath) Then
                Response.Clear()
                Response.ClearContent()
                Response.ClearHeaders()
                Response.AddHeader("Content-Disposition", "attachment;filename=""" & Anexo & """")
                Response.TransmitFile(Server.MapPath("~/Anexo_OS/" + Anexo))
                Response.Flush()
                Context.ApplicationInstance.CompleteRequest()
                Response.Close()
            End If

        Loop
        Msg.ShowMessage("Download concluded!!!")
    Else
        Msg.ShowMessage("Don't have attachment to download!!!")
    End If
Catch ex As Exception
    Msg.ShowMessage("Error to download the file: " & ex.Message)
End Try
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,364 questions
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,763 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,628 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 59,056 Reputation points
    2023-10-27T15:28:55.3766667+00:00

    A http request (like file download) can only return one response. Your only option is to zip files into one download file.


0 additional answers

Sort by: Most helpful