views:

493

answers:

3

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?

+2  A: 

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});

Mark McGregor
What you said is true, but that ain't it.
AngryHacker
+2  A: 

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

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

Not sure why.

AngryHacker
Is this running under HTTPS?
wweicker
No, it does not.
AngryHacker
A: 

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.

Birger Thieren