I have an ASP.NET page where I'm generating an Excel spreadsheet and sending that in the response (content-disposition header). That part works great, but I have a button that never becomes re-enabled because the original page isn't part of the response.
Here's the function I'm using:
Public Shared Sub WriteToResponse(ByVal theWorkBook As Workbook, ByVal FileName As String, ByVal resp As HttpResponse)
Dim theStream As New System.IO.MemoryStream()
theWorkBook.Save(theStream)
Dim byteArr As Byte() = DirectCast(Array.CreateInstance(GetType(Byte), theStream.Length), Byte())
theStream.Position = 0
theStream.Read(byteArr, 0, CInt(theStream.Length))
theStream.Close()
resp.Clear()
resp.AddHeader("content-disposition", "attachment; filename=" & FileName)
resp.BinaryWrite(byteArr)
resp.End()
End Sub
I tried not clearing the response and using AppendHeader instead of AddHeader, but the response still contains only the file.
What am I missing? Do I need to use a different header? I found this unanswered question on the ASP.NET forums; sounds like my problem.