1

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

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

2
  • 1
    How is this different than just dropping the PDF on the server and having it served via URL? Is this a dynamically generated PDF? Commented Sep 17, 2008 at 16:26
  • @spoon16, there is some security issues with this approach, as any one can see the pdf url from page's viewsource. Since these are static files(.pdf,.htm...etc) they will serve directly by the IIS, to whoever requesting this URL, without checking whether they are logged in or not. Commented Sep 20, 2012 at 5:52

3 Answers 3

2
  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", "attachment: 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.

Sign up to request clarification or add additional context in comments.

Comments

0

Write the binary to the output stream, Response.OutputStream. Then just add the header Content-Disposition header.

Comments

-1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.