0

I want to return a pdf file as response to some button click. I succeeded to send the pdf file, but when i try to save it via the browser, it won't let me save it as a .pdf file (but as .aspx file)

here's the code:

Dim myWebClient As WebClient = New WebClient()
Dim myDataBuffer As Byte() = myWebClient.DownloadData(LocalImageURL) ' LocalImageURL is some path to a pdf file
Response.ContentType = "application/pdf"

Response.BinaryWrite(myDataBuffer)
Response.Flush()

Response.End()

if I am adding also the following line before writing the byte array:

Response.AddHeader("content-disposition", "attachment;filename=report.pdf")

it does the trick, but the problem is that the page remains stuck (looks like it still waits for server response to come)

shasi kanth
  • 6,987
  • 24
  • 106
  • 158
itay312
  • 1,518
  • 4
  • 24
  • 36

1 Answers1

0

This has been asked and answered before. Details are at the link below:

asp.net VB.net file download handler not work properly

Community
  • 1
  • 1
Prescott Chartier
  • 1,519
  • 3
  • 17
  • 34