User-883001733 posted
I want to download a file from an ASP webforms page.
If I use a WebForm without a MasterPage everything is fine, I have a LinkButton with this:
Private Sub linkDOWNLOAD_Click(sender As Object, e As EventArgs) Handles linkDOWNLOAD.Click
Dim filePath = "C:\files\" + DropDownList1.SelectedItem.Value
Dim fileStream As Stream = streamClient.someWebServiceReturningFileStream(filePath)
Dim buffer(65536) As Byte
Dim bytesRead = 0
Response.BufferOutput = False
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ClearHeaders()
HttpContext.Current.Response.ContentType = "application/octet-stream"
HttpContext.Current.Response.AddHeader("Content-Disposition",
"attachment; filename=" + DropDownList1.SelectedItem.Value)
bytesRead = fileStream.Read(buffer, 0, buffer.Length)
While (bytesRead > 0)
If (Response.IsClientConnected) Then
Response.OutputStream.Write(buffer, 0, bytesRead)
Response.Flush()
buffer = New Byte(65536) {}
bytesRead = fileStream.Read(buffer, 0, buffer.Length)
Else
bytesRead = -1
End If
End While
Response.Flush()
Response.Close()
Response.End()
End
As I said this works fine and the browser open the dialog to download the file, but if I try the same code in a button inside a content page within a MasterPage, then nothing happens.
The Master page has this inside:
...
<asp:UpdatePanel ID="updatePanelBODY" runat="server">
<ContentTemplate>
<asp:ContentPlaceHolder ID="contentBODY" runat="server">
</asp:ContentPlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
...
The Content page has this inside:
<asp:Content ID="Content2" ContentPlaceHolderID="contentBODY" runat="server">
<asp:LinkButton ID="linkDOWNLOAD" runat="server">Download File</asp:LinkButton>
</asp:Content>
I don't know how to solve this and every example I have found is based on webforms without any master page.
Thanks for your help.