Generating Report from a FlexReport on the Controller

Posted by: mcherry on 15 October 2020, 12:13 am EST

    • Post Options:
    • Link

    Posted 15 October 2020, 12:13 am EST

    My use case is that I want to select an existing report built with the FlexReport Builder, set the parameters, generate the report, convert the output to PDF, and return the PDF .

    Using the code below works without issue in a non-ASP client, but causes errors it seems with the server not registering the ADO.NET providers - any of them, it seems. It doesn’t matter if I use ODBC or OLEDB - but the report needs to query the database.

                C1.Win.FlexReport.C1FlexReport report = new C1.Win.FlexReport.C1FlexReport();
                report.Load(@"C:\Test\test.flxr", "test");
                C1.Win.FlexReport.DataSource dataSource = new C1.Win.FlexReport.DataSource();
                dataSource.Name = "Main";
                dataSource.ConnectionString = @"[redacted]";
                dataSource.DataProvider = C1.Win.FlexReport.DataProvider.OLEDB;
                report.DataSources.Add(dataSource);
    
                report.Parameters.FindByName("BeginDate").Value = "1/1/2020";
                report.Parameters.FindByName("EndDate").Value = "10/1/2020";
                report.Parameters.FindByName("Practice").Value = "1";
                report.Generate();
    
                
                C1.Win.C1Document.Export.PdfFilter filter = new C1.Win.C1Document.Export.PdfFilter();
                filter.Stream = new System.IO.MemoryStream();
                report.RenderToFilter(filter);
                return (filter.Stream as System.IO.MemoryStream).ToArray();
    

    I’m not necessarily looking to resolve the ADO.NET driver issue. I spent most of yesterday trying various ways of addressing that issue. It doesn’t seem to care about the CPU architecture, which is the only answer that seems to ever be provided - “run it in 32 bit mode.” Doesn’t help, I’ve tried.

    Now the data comes from a Stored Procedure. I can query the DB just fine to get the data into a DataSet, and I see the FlexReport builder can “connect to an external object” - but that appears to require a dll model and I really don’t want to build out dozens of model libraries that I have to manage any time a change is requested to any of the reports.

    So given the above use case, are there other methods available I could use here? Is there a recommended way for generating a report server-side?

  • Posted 15 October 2020, 4:37 am EST

    So after more reading and testing I’ve found that I can set the Recordset directly with a DataTable object. This snippet works for what I’m trying to do.

    C1FlexReport report = new C1FlexReport();
                    report.Load(path, ReportName);
                    C1.Win.FlexReport.DataSource dataSource = new C1.Win.FlexReport.DataSource();
                    dataSource.Name = "Main";
                    dataSource.Recordset = ds.Tables[0];
                    report.DataSources.Add(dataSource);
                    report.Generate();
    
                    C1.Win.C1Document.Export.PdfFilter filter = new C1.Win.C1Document.Export.PdfFilter();
                    filter.Stream = new System.IO.MemoryStream();
                    report.RenderToFilter(filter);
                    byte[] result = (filter.Stream as System.IO.MemoryStream).ToArray();
                    return result;
    
  • Posted 15 October 2020, 12:53 pm EST

    Hi,

    Thanks for the information. We are glad to know that your issue has been resolved.

    Regards,

    Manish Gupta

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels