cancel
Showing results for 
Search instead for 
Did you mean: 

Another question about export formats

Former Member
0 Kudos

I have a report that needs to be exported to TAB delimited format...

I have CR Developer 11.5.

I have VS 2005.

I'm a programming neophyte.

I can create my reports and then create a simple ASPX page with a viewer and a report source, with no problem.

But I have no clue how to modify the code to add export formats. Is it even possible? If possible -- where do I start?

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Martha,

Try with this:

ReportDocument Rdoc = new ReportDocument();

Rdoc.Load(Server.Mappath("CrystalReport"));

Rdoc.ExportToDisk(ExportFormatType.TabSeperatedText, "C:\Windows\temp
ExportedReport.txt");

/Give the format type according to your choce, path of exported file to be saved/

Hope this helps!!

Regards,

Shweta

Edited by: Shweta Sharma on Sep 8, 2008 11:04 PM

Former Member
0 Kudos

Sorry, but I am really a neophyte: I have NO IDEA where to put that code. I have an ASPX file, and a VB file to go with it.

I would learn this better -- if people didn't need these reports right now. I will learn it, at some point, but just need to make the report available.

Can you help?

Thanks

Former Member
0 Kudos

Hi Martha,

You can download sample codes:

from [here|https://boc.sdn.sap.com/codesamples]

Hope this helps!!

Regards,

Shweta

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Martha,

With all above's suggestion i would like to give you the link of [Dev library|https://boc.sdn.sap.com/node/7770]

Hope this helps!!

Regards,

Shweta

Former Member
0 Kudos

Shawn, Thanks for the instructions, but I'm not using a report document viewer object -- I'm using the CrystalReportViewer. Will this still work? I tried to add the code, and was not given the ExportToDisk method (property?) as an option to a viewer object. (Sorry, I really am a newbie.)

Shweta, thanks for the examples. None of the report viewer example handle exporting, though.

I'm thinking I need to NOT use the CrystalReportViewer?

Former Member
0 Kudos

Please ignore this.

repeated message posted - hence removing this entry to keep the focus.

Edited by: AG on Sep 9, 2008 11:13 PM

Former Member
0 Kudos

HI Martha,

In order to use the methods available under Reportdocument object or Viewer object model you need to include the proper namespaces, in our case it will mainly be:

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

using CrystalDecisions.Web; // for web based application

using CrystalDecisions.Windows // for windows based application.

Have you added these namespaces in your code?

Here is a sample code in c# that might help.

// Adding namespaces
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Windows


ReportDocument crReport=new ReportDocument(); 
crReport.Load("c:\\Windows\\Report.rpt");

//to display the report
crystalReportViewer1.ReportSource =crReport; 

//Exporting the report in pdf format
crReport.ExportToDisk(ExportFormatType.PortableDocFormat,"c:\\temp\\myRpt.pdf");

If you want to use the Viewer Object model then try this:

ExportOptions crExportOptions=new ExportOptions();
DiskFileDestinationOptions crDiskDestOpt=new DiskFileDestinationOptions();
			
crExportOptions=crReport.ExportOptions;
crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
crDiskDestOpt.DiskFileName =@"c:\temp\myreport.pdf";
crExportOptions.ExportDestinationOptions=crDiskDestOpt;
				
crReport.Export();

you said:

I'm thinking I need to NOT use the CrystalReportViewer?

I am not sure I understood that properly, however just wanted you to know that when you use this code you will not require to use the Export button in the viewer toolbar. You can put it in a button for example and get the report exported in a format in the click event.

Does this help ?

Regards,

AG.

Former Member
0 Kudos

This all looks very helpful but again, unfortunately, I don't know where to put this code. Does it go in my ASPX file, or my ASPX.VB file?

I've tried inserting sample code before, and it's clear I'm not putting it in the right place -- I'll go ahead and attempt this, but any clues would be much appreciated.

Former Member
0 Kudos

Hi Martha,

Write code on page load event.

You can also write tha same code for button_click events.

Regards,

Shweta

Former Member
0 Kudos

HI Martha,

I will try to explain what Shweta suggested a bit more, when you create a sample application in .Net you will get a form to design on. On the form if you double click on it, it will take you to the code behind page, these pages will have the extension as vb or cs according to the language you have selected. So it will be in ASPX.VB in your case. But the code provided above is in C#. Please change the syntax accordingly.

In the code behind page apply the code in page load or button click or any other event as per your wish.

In the form in design mode drag and drop a viewer and refer to its name in the code to pass the ReportSource as reportdocument object.

Better?

Regards,

AG.

former_member203619
Contributor
0 Kudos

Hi Martha,

A few comments / notes:

- From your notes - you appear to want to add additional export formats to the viewer. This is not possible. The only way to do this is to create your own button which exports the report to the desired format when clicked. But it is not possible to add additional formats to the ones already in the list on the viewer.

- The code given by Shweta is for exporting to CSV without a viewer.

- Since you already have a report being loaded - you should have a reportdocument object already which you are using to load the report. What you will need to do is add a button to your page and add the exporting code to it. Specifically - the line

"Rdoc.ExportToDisk(ExportFormatType.TabSeperatedText, "C:\Windows\temp

ExportedReport.txt");"

Notes:

-This assumes that Rdoc is your reportdocument object and that you have loaded ther report already.

-If you are using a windows app - then that would be all that is needed

-If you are using a web app - then you will want to place the reportdocument object in session so that you don't have to reload it on every postback (which occurs anytime a button is pushed)

Shawn