Skip to Content
avatar image
Former Member

How do I iterate through a rendered Crystal Report (page by page)

We are upgrading our product's report generation application from Crystal Reports 9 to

Crystal Reports for VS2015, and incidentally rewriting our ActiveX based CRViewer app into a C# CrystalReportsViewer (which will incidentally solve some 32-bit VB6 email issues too). I'm almost done with the conversion but I'm stumped on our email report to recipients custom action.


In the CR9 viewer, we wired certain events (GroupSection_Format, PageSection_Format, and HeaderSection_Format) and kept track of the GroupHeader1 value to manually keep track of what pages went to which customers, so we could then export specified pages per customer and email a customer a bill, contract, letter, or whatever.


In the CRforVS2015 CrystalReportsViewer, I see no way to iterate through the report as its generating (can't seem to wire events for BeforeFormatPage or FormatSection) or to iterate through the report after its generated. How am I supposed to do this then? (Generate a report for a duration and send report PDF to pertinent client through email.) Many of our clients depend on this process. It save a lot of time and reduces human errors by automating email generation from stored data.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Sep 28, 2017 at 09:32 PM

    Hi John,

    You are not the first person that used those events, you are the second person who has run into this.

    I asked DEV for the first Customer, an OEM Partner, if we could add that event trigger and they said no, the problem is with the conversion from ActiveX to .NET it simply doesn't allow interaction of this type in the Event handlers of the CR Formatting Engine.

    The only work around would be to use the Record Selection Formula API and modify it for each customer. Run a separate Query to the server to fill a list of Customers and then modify the Selection formula for each:

    CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
    CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc;

    Open report, log on etc....

    CrystalDecisions.ReportAppServer.DataDefModel.ISCRFilter myRecordSelectionWithComments;
    myRecordSelectionWithComments = rptClientDoc.DataDefController.DataDefinition.RecordFilter;
    if (myRecordSelectionWithComments.FreeEditingText != null)
    {
    //myRecordSelectionWithComments.FreeEditingText = rptClientDoc.DataDefController.RecordFilterController.GetFormulaText();
    btnRecordSelectionForm.Text = "\nWith Comments:\n" + myRecordSelectionWithComments.FreeEditingText.ToString();
    btnRecordSelectionForm.AppendText("\n\n");
    btnRecordSelectionForm.AppendText("\nWithout Comments:\n" + rpt.RecordSelectionFormula.ToString());
    btnRecordSelectionForm.AppendText("\n");
    //myRecordSelectionWithComments.FreeEditingText = "{TStat.TArt_Cod} = \"A823/001\"";
    //rpt.RecordSelectionFormula = "{TStat.TArt_Cod} = \"A823/001\"";
    //IsRpt = false;
    }
    else
    btnRecordSelectionForm.Text = "No Record Selection formula";

    Once the filter is applied then export to file and e-mail the result to the customer.

    Another option is to use the CrystalDecisions.CrystalReports.Engine.DataDefinition.SavedDataSelectionFormula

    It would allow you to use the same multi-user report and add filtering afterwards. I don't have any sample code on using it, I used to but can't find it anymore.

    Don

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 05, 2017 at 05:15 PM

    Don,

    Thanks sooo much!! Your answer was the piece of information I needed. I didn't look for an answer until yesterday and in my excitement of coding the answer, couldn't respond until this afternoon.

    I took your advice and for our reports that we burst, then when the user selected to email the report to recipients, I iterated through the list of GroupHeader1 values (that I retrieve from the Dataset) and exported the report to a PDF after setting a formula in the RecordSelectionFormula for the ReportDocument.


    Thanks again,
    John

    Add comment
    10|10000 characters needed characters exceeded