Skip to Content

Upgrade to 13.0.18 Caused Some Problem

I just upgraded, and three things went wrong and broke my app. I am generating reports in an ASP.NET website, under program control, and sending them to the browser (not using the report viewer).

First problem: report output to html used file extension '.html' even though I had set it to '.htm' in my code (htmlOptions.HTMLFileName = "some_report.htm"). This caused 404 errors for my users. Easily fixed, but pretty annoying.

Second: The ExportToStream method changed. I was doing this:

MemoryStream reportStream = reportDocument.ExportToStream(ExportFormatType.PortableDocFormat) as MemoryStream;

It had been working for years, but now, my reportStream was null. No longer a MemoryStream. I fixed this by dealing with it as a plain Stream - again, easy fix, but annoying.

Third (and worst): My RecordSelectionFormula is getting blown away when I try to modify it. I do this:

reportDocument.DataDefinition.RecordSelectionFormula = "(" + reportDocument.DataDefinition.RecordSelectionFormula + ") and (" + additionalFormula + ")";

This also has been working for years - the formula pieces are all correctly formatted. I watch this line of code in the debugger. Before it executes, I can see that

reportDocument.DataDefinition.RecordSelectionFormula is set to a formula which includes the report parameters. The additionalFormula value is set to a proper expression. After it executes, ReportDocument.DataDefinition.RecordSelectionFormula is an empty string. So my report is no longer filtered, and returns hundreds or thousands of times the number of rows it should. This one I haven't fixed yet - still playing with it to see what I can do.

I read the release notes for this update and the previous ones which I had missed. None of this was mentioned, unless I missed something...

So, I am supposed to ask a question. Here are two:

1 - Are these expected changes? Did I miss something or misunderstand something?

2 - why is my simple string concatenation for the RecordSelectionFormula resulting in an empty string?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Best Answer
    Jan 23, 2017 at 04:47 PM

    Hi Ray,

    Regarding the record selection formula, uses this:

    // Record selection formula with comments included can only be retrieve via RAS
    CrystalDecisions.ReportAppServer.DataDefModel.ISCRFilter myRecordSelectionWithComments; // = new CrystalDecisions.ReportAppServer.DataDefModel.;
    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("\nWithout Comments:\n" + rpt.RecordSelectionFormula.ToString());
    myRecordSelectionWithComments.FreeEditingText = @"(" + reportDocument.DataDefinition.RecordSelectionFormula + ") and (" + additionalFormula + ")";

    //IsRpt = false;
    btnRecordSelectionForm.Text = "No Record Selection formula";

    Try the formula in CR Designer, it it doesn't work there it's not going to work in code.


    Add comment
    10|10000 characters needed characters exceeded

  • Jan 14, 2017 at 02:45 PM

    I found my way to the archived discussion forums and saw that the RecordSelectionFormula problem has been reported a number of times. Most of the info there seemed to be for the report viewer, which I am not using, but I got some ideas. I changed my code to use RecordFilterController.Modify. This didn't help - my formula was still not applied to the report. RecordSelectionFormulaRaw was updated with the formula info I added, but RecordSelectionFormula was not. A couple of threads suggested calling Verify() or Refresh(). Both of these caused my report to fail (missing parameter value error). Is there a way to do this, or do I need to revert to the previous version?

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 19, 2017 at 03:16 PM

    Please see this archived discussion for more info about exporting to MemoryStream:


    Add comment
    10|10000 characters needed characters exceeded

  • Jan 23, 2017 at 07:57 PM

    I had seen this sample code in other messages, and it is basically what I tried to do last week. It is not working for me. The way my report system works, it calls this code multiple times for some reports to add multiple filters. On the first call, the filter (RecordSelectionFormula or FreeEditingText) is the same as the selection formula saved with the report. I add my additional filter to it, and it seems fine. But, when I do it again, the report filter goes back to the original selection formula saved in the report - the filter I added to it is gone.

    I logged the formulas I was creating and pasted them directly into the report - they worked correctly

    I think this leads me to a fix - rather than calling this multiple times, it looks like I need to build up a formula string and apply it all at once. Doing that, it looks like I can just set RecordSelectionFormula once and it will work (I hard-coded a test case and it worked).

    Does this sound correct to you? Are there better options that would allow me to avoid reworking my report system?

    What was the reason for this change? I have been using this same code for years without any problem. I was using version 13.0.9 before I move to version 18, and that was still ok.

    In the sample code, I don't understand what 'btnRecordSelectionForm' is - is this part of the report viewer? I don't use the report viewer.

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 21, 2017 at 05:43 PM

    btnRecordSelectionForm is a text box I use to display the info.

    Look at your code, make sure you are not re-initializing the viewer or report object after the first change. Only reason it woudl reset back to the original.


    Add comment
    10|10000 characters needed characters exceeded

  • May 18, 2017 at 09:51 PM

    I had to set this aside for a while, but now I am back. I have upgraded to version 20, which still has the same problem. I have found a simple solution which I am posting here in case anyone else runs into this, and also to get some validation that this is a good approach. I am using RecordSelectionFormulaRaw to get the current formula. I add my additional formula to it (wrapping everything in parentheses), and then set RecordSelectionFormula to the new value. This may get called multiple times for a report, and it just continues to add more to the formula each time.

    Note that if I inspect the value of RecordSelectionFormula before the first time this is called, it includes the formula(s) for any report parameters. After I set the value in the code below, RecordSelectionFormula is always an empty string. The 'Raw' version has the full formula, including parameters and the additional formula pieces I have added with this code. The important thing is that the full formula is applied to the report.

    So, please take a look at this and let me know if this is a good plan, or if I might have another problem. I am concerned, because as I said before, my original code worked correctly for years until I upgraded to version 18.

    if (reportDocument.DataDefinition.RecordSelectionFormulaRaw == string.Empty) {
    	reportDocument.DataDefinition.RecordSelectionFormula = newFormula;
    else {
    	reportDocument.DataDefinition.RecordSelectionFormula = "(" + reportDocument.DataDefinition.RecordSelectionFormulaRaw + ") and (" + newFormula + ")";
    Add comment
    10|10000 characters needed characters exceeded