Home > .net 2.0, c# > Response and try/catch Statements

Response and try/catch Statements

March 1, 2007

Writing a few methods for writing out the PDFs from ActiveReports, I came across an odd behavior in IE.  Before I added in thet try/catch statements, the PDFs would open just fine in the browser using the inline viewer (as specified); however, after adding the try/catch, it would open up a Save As dialog with the note that the browser felt the file didn’t match the extention.

Save As dialog for 'mishandled' PDF

So, what’s the fix?  After a bit of dinking around, it seemed the issue was that the Response object was losing scope during that try/catch and never being ‘ended’ when it was ‘finally’ done.

The fix was to add a finally clause and add Response.End to that section rather than within the method I had to stream the PDF memorystream OR within the try statement.

finally
{
     Response.End();
}

 

Tags: ,

Categories: .net 2.0, c#
%d bloggers like this: