Skip to Content
author's profile photo Former Member
Former Member

Strange Issue with using ExportToHttpResponse for exporting to Excel

Hi,

We are working with BO XI R2 with .Net 2.0.

We are using ExportToHttpResponse method to export the Crystal Report to pdf/excel and directly opening the export in a browser window.

Code being used is as follows :

For pdf : rd.ExportToHttpResponse(ExportFormatType.PortableDocFormat, oResponse, false, Name);

For Excel : rd.ExportToHttpResponse(ExportFormatType.Excel, oResponse, false, Name);

where 'rd' is ReportDocument instance.

The strange issue here is that for pdf output this works as desired and the exported report is directly opened in the browser window. However when it comes to Excel ; it does not open the exported file in the browser window and gives a prompt to open/save file. Even if the 'asAttachment' parameter of ExportToHttpResponse method is set to false it still is sending the exported file as an attachment to the browser and not opening it directly (as it is happening in the case of a pdf export )

Do we need to set the Response.ContentType to excel ; if yes then why it is working in case of pdf.

Can any one please advise about this strange issue .

Thanks

Vinayak Vidhate

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on Oct 15, 2008 at 02:26 PM

    Try the following:

    System.IO.MemoryStream oStream = (System.IO.MemoryStream)crReport.ExportToStream(ExportFormatType.Excel);

    Response.Clear();

    Response.ClearHeaders();

    Response.AddHeader("Content-Disposition", "inline;filename=exportedreport.xls");

    Response.ContentType = "application/vnd.ms-excel";

    Response.BinaryWrite(oStream.ToArray());

    Response.Flush();

    Response.Close();

    The code works on my machine.

    If that does not help, consider using a utility such as [Charles|http://www.charlesproxy.com] or [Fiddler|http://www.fiddlertool.com/fiddler] to see what's going on.

    Ludek

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      >

      > Hi, Vinayak;

      >

      > How a document is handled is determined by Windows' settings, not your program.

      >

      > - Open Windows Explorer, and go to the Tools menu, and choose Folder Options

      > - Go to the File Types tab

      > - Go to the entry for XLS Microsoft Excel Spreadsheet

      > - Click the Advanced button

      > - In the Actions window, select Open, and uncheck the "confirm open after download" option.

      >

      > You should now not be prompted to save the file, and it should open automatically.

      >

      > Best Regards,

      > Jonathan

      Bang on the target Jonathan . Thanks . The issue seemed to be solved now.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.