Crystal Reports exception when calling ExportToDisk

crystal-reportsexception

I'm getting some weird behavior with Crystal Reports (version distributed with Visual Studio 2008). I can view the report normally, but attempts to use ExportToDisk fail with the following exception:

CrystalDecisions.CrystalReports.Engine.InvalidArgumentException:

This group section cannot be printed
because its condition field is
nonexistent or invalid. Format the
section to choose another condition
field. Error in File
C:\DOCUME~1\gbuehler\LOCALS~1\Temp\Report
{2FD9516D-0FD4-4D20-A326-D21EB762EB9E}.rpt:
Invalid group condition. —>
System.Runtime.InteropServices.COMException
(0x8000020B):

This group section cannot be printed
because its condition field is
nonexistent or invalid. Format the
section to choose another condition
field. Error in File
C:\DOCUME~1\developer\LOCALS~1\Temp\Report
{2FD9516D-0FD4-4D20-A326-D21EB762EB9E}.rpt:
Invalid group condition. at
CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions
pExportOptions, RequestContext
pRequestContext) at
CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext
reqContext) — End of inner
exception stack trace — at
CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception
e) at
CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext
reqContext) at
CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext
reqContext) at
CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext
reqContext) at
CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToDisk(ExportFormatType
formatType, String fileName) at
LSPayroll.MainForm.btnSendCanadian_Click(Object
sender, EventArgs e) in C:\Documents
and Settings\developer\My
Documents\Visual Studio
2008\Projects\MyProject\MyProject\MainForm.cs:line
277

A cursory search for Invalid Group Condition returns other users looking for solutions and recommendations to recreate the report. Can someone give a logical reason why the report can be viewed normally, but ExportToDisk fails with an exception?

Not sure if it helps, but this is the code I'm using to create the report document and export:

// build a crystal reports document in memory and use the crystal 
// reports library to export as a PDF
ReportDocument reportDocument = new ReportDocument();
reportDocument.Load(reportPath);
reportDocument.SetDataSource(data);
reportDocument.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, "payroll.pdf");

Best Answer

Struggled to find a solution to this problem

The solution that worked for me

In the statement

reportDocument.SetDataSource(data);

ensure that 'data' is a reference to a DataSet and not a DataTable.