You must Sign In to post a response.
  • Category: ASP.NET

    Mr. Ramasamy.N thanks to u... but.........

    select multplie file in listbox. it take first select item in listbox. next item error in

    "Server cannot append header after HTTP headers have been sent."
    how is handle.

    I want Multiple files Download in same time.
    pls hlp me



    LstFile is new listbox


    Protected Sub btnDownload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDownload.Click
    Dim k As String = LstFile.SelectedItem.Value
    For i As Integer = 0 To LstFile.Items.Count - 1
    If LstFile.Items(i).Selected = True Then
    Dim fs As FileStream
    Dim filesize As New Long
    Try
    fs = New FileStream(LstFile.Items(i).Value, FileMode.Open)
    filesize = fs.Length
    Dim buffer As Byte() = New Byte(CInt(filesize) - 1) {}
    fs.Read(buffer, 0, CInt(filesize))
    fs.Close()
    Response.Buffer = True
    'Dim attachFileName As String = LstFile.SelectedItem.Value.Substring(LstFile.SelectedItem.Value.LastIndexOf("\") + 1)
    Response.AddHeader("Content-disposition", "attachment;filename=" & LstFile.SelectedItem.Text & "")
    Response.ContentType = "application/octet-stream"
    Response.BinaryWrite(buffer)
    Response.Flush()
    Response.Close()
    Catch ex As Exception
    End Try
    End If
    Next


    adv thanks
  • #218862
    initially selected item should be set to false selection then go for next selected item.as defined in the code below
    Protected Sub btnDownload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDownload.Click
    Dim k As String = LstFile.SelectedItem.Value
    For i As Integer = 0 To LstFile.Items.Count - 1
    If LstFile.Items(i).Selected = True Then
    Dim fs As FileStream
    Dim filesize As New Long
    Try
    fs = New FileStream(LstFile.Items(i).Value, FileMode.Open)
    filesize = fs.Length
    Dim buffer As Byte() = New Byte(CInt(filesize) - 1) {}
    fs.Read(buffer, 0, CInt(filesize))
    fs.Close()
    Response.Buffer = True
    'Dim attachFileName As String = LstFile.SelectedItem.Value.Substring(LstFile.SelectedItem.Value.LastIndexOf("\") + 1)
    Response.AddHeader("Content-disposition", "attachment;filename=" & LstFile.SelectedItem.Text & "")
    Response.ContentType = "application/octet-stream"
    Response.BinaryWrite(buffer)
    Response.Flush()
    Response.Close()
    Catch ex As Exception
    End Try
    LstFile.Items(i).Selected=False
    End If
    Next

  • #218867
    Thanks to k.prabhakar varma

    LstFile.Items(i).Selected=False is a no problem.

    i change
    Response.AddHeader("Content-disposition", "attachment;filename=" & LstFile.items(i).Text & "")
    in that place.

    My Error is
    "Server cannot append header after HTTP headers have been sent."

    how is handle.

    Thanks to you

  • #218868
    Thanks to k.prabhakar varma

    LstFile.Items(i).Selected=False is a no problem.

    i change
    Response.AddHeader("Content-disposition", "attachment;filename=" & LstFile.items(i).Text & "")
    in that place.

    My Error is
    "Server cannot append header after HTTP headers have been sent."

    how is handle.

    Thanks to you

  • #218899
    try this
    Response.AddHeader("Content-disposition", "attachment;filename="& LstFile.items(i).Text )


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.