Tutorial :Pushing out a PDF file to IE from an ASP.NET 3.5 site


My application pushes out a PDF file to a popup (e.g. no menu/toolbar) browser window (in response to the user clicking a button). This works for every browser out there except for IE7. In IE7, all I get is a blank window.

Here is the server-side code that pushes out the PDF:

private void StreamPDFReport(string ReportPath, HttpContext context)  {      context.Response.Buffer = false;      context.Response.Clear();      context.Response.ClearContent();      context.Response.ClearHeaders();                // Set the appropriate ContentType.      context.Response.ContentType = "application/pdf";      context.Response.AddHeader("Content-Disposition", "inline; filename=Report.pdf");      context.Response.Cache.SetCacheability(HttpCacheability.NoCache);                // Write the file directly to the HTTP content output stream.      context.Response.WriteFile(ReportPath);      HttpContext.Current.ApplicationInstance.CompleteRequest();      //context.Response.End();  }  

On the client side, when the user presses the button, the following happens in the onClick handler:

onclick="window.open('RptHandler.ashx?RptType=CaseInfo', 'Report', 'top=10,left=10,width=1000,height=750')

Am I missing something really basic? Why does it work in every browser but not IE?


It turns out that the following statement causes IE to not display the PDF:


Not sure why.


With IE7 we found you needed to add an additional header 'content-length' set to the size of the PDF your sending. something like:

Response.AddHeader("content-length", {size of the pdf});


Seems like context.Response.Cache.SetCacheability(HttpCacheability.NoCache); will only work when using IIS7.

I changed it to context.Response.AddHeader("Cache-Control", "no-cache"); and it seems to be working with IE7 and IE8.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »