tags:

views:

3282

answers:

5

I'm looking for a way to stream a pdf from my server to the browser using .NET 2.0 (in binary).

Edit: I'm trying to grab an existing pdf from a server path and push that up as binary to the browser.

+1  A: 

write the binary to the output stream. Response.OutputStream. then just add the header Content-Disposition header.

Darren Kopp
A: 

Is this an existing PDF file stored on the server's filesystem or are you trying to generate one on-the-fly?

richardtallent
A: 

You can just setup a handler or a page that set's the correct response type and output the pdf to the response output buffer.

Quintin Robinson
+2  A: 
  1. Set Content-Type: Response.ContentType = "application/pdf"
  2. Set ContentDisposition, if you want to give a new name for the file: Response.Headers.Add("Content-Disposition", "attachement: filename=file.pdf");
  3. Write the content, using Response.OutputStream as Mr. Kopp said.

Step 2 is not strictly necessary, but it's probably a good idea if you don't want the browser to try to save the PDF with the same name as your ASPX file.

foxxtrot