Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 845
AngryHacker Avatar asked May 09 '09 17:05

AngryHacker


1 Answers

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

context.Response.Cache.SetCacheability(HttpCacheability.NoCache); 

Not sure why.

like image 151
AngryHacker Avatar answered Oct 07 '22 17:10

AngryHacker