Issues sending output of Crystal Reports to a browser
Posted on 2007-08-11
I have written an asp.net application (C#) which uses crystal reports to generate reports in excel, pdf, or rtf format. It then sends these files to the browser for display. This works perfectly on most machines, but every now and then the machines won't display the file. Sometimes the browser beeps and closes the window AFTER opening a new window and downloading the file (even if all popup blockers are off) My question is why, and how do I fix this?
Some other details... Solutions that have worked so far but are either not good enough or are unexplainable...
1) On most machines with this problem... unibstalling adobe and reinstalling fixes the problem for all 3 file types. I understand why it fixes pdf, but....
2) If I set "always prompt for file download" under internet settings, the user gets a download dialog and can save it or even (sometimes) open it straight in this browser. This works, but it makes the app inelegant.
Is there a better way?
PS. Here is the C# code for display (which is basically a copy of suggested code from Business Object support)
private void ShowMyReport()
//Clear the response, so we can just send the file
//Set up the format of the export
Response.ContentType = "application/pdf";
Response.AppendHeader ("Content-Disposition", "Filename=Report.pdf");
extension = ".pdf";
Response.ContentType = "application/xls";
Response.AppendHeader ("Content-Disposition", "Filename=Report.xls");
extension = ".xls";
Response.ContentType = "text/rtf";
Response.AppendHeader ("Content-Disposition", "Filename=Report.rtf");
extension = ".rtf";
//Now set up where to get the file from.
string exportFileName = Session["ExportFileName"].ToString();
//Dump the file to the web browser
//Now get rid of the pesky file off the server.
//Let the page display.