cancel
Showing results for 
Search instead for 
Did you mean: 

Strange Issue with using ExportToHttpResponse for exporting to Excel

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

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

Former Member
0 Kudos

>

> 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

Thanks for the response Ludek .

I was going through some othere threads and saw that ExportToHttpResponse is more preferred over ExportToStream . I even checked for setting up the Response.ContentType to Excel . I think I shoulfd give it a try to use ExportToStream.

Let me know if any one else has any other suggestion(s).

Former Member
0 Kudos

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

Former Member
0 Kudos

>

> 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.

Answers (0)