tags:

views:

49

answers:

3

I am trying to open a PDF document to display within IE6. I am using the following snippet:

response.ContentType = healthMedia.MediaKey.MimeType;
response.ClearHeaders();     

response.AddHeader("Content-Disposition", "inline; filename=" + mediaKeyId);

int contentLength = healthMedia.Content.Length;
response.AppendHeader("content-length", Convert.ToString(contentLength));
response.OutputStream.Write(healthMedia.Content, 0, contentLength);

healthMedia.MediaKey.MimeType; is equal to 'application/pdf'

This brings up the Save dialog. If I comment out Response.ClearHeaders(); I get a new window to popup but it's contents is a bunch of jibberish (random encoding text).

How can I get IE6 to open the PDF correctly?

-Nick

A: 

Have you tried Response.End() and also Response.Buffer = true? You may also need to set a caching policy.

Chris S
This is from memory, I prefer providing PDFs as attachments to avoid freezing their browser with the terrible Acrobat Reader plugin.
Chris S
Thanks Chris.. after clearing the header the browser was attempting to download the pdf. The plugin was missing. I am currently adding this header response.AppendHeader("content-length", Convert.ToString(contentLength)); Is that what you are suggesting?
Nick
Also ending the response and making it buffered is needed in IE6 (I think)
Chris S
A: 

In case it helps, here's a method I've used before to render in-browser PDFs...

lance
A: 

Use response.BinaryWrite() instead of response.OutputStream.Write()

Josh Stodola
BinaryWrite does exactly what he's doing already, and he needs the length anyway
Chris S