Search code examples
c#crystal-reports

Import .rpt and .cs file of Crystal report to generate report


I can import the .rpt and .cs file of crystal report via OpenFileDialog, but i dont know how i can use that to generate report. is it possible to do that just importing the .rpt and .cs and you can use the imported file to generate report?


Solution

  • Add a reference to Crystal reports SDK (CrystalDecisions.CrystalReports.Engine) https://wiki.scn.sap.com/wiki/display/BOBJ/Crystal+Reports%2C+Developer+for+Visual+Studio+Downloads

    Then open the report

    using (ReportDocument rep = new ReportDocument())
    {
         //Open report
         rep.Load("SomeReport.rpt", OpenReportMethod.OpenReportByTempCopy);
    
         //rep.PrintOptions = ...
         rep.PrintToPrinter(1 /*NumCopies*/, true, 1, 9999);
    
         //or
         rep.ExportToDisk(ExportFormatType.PortableDocFormat, "SomeReport.pdf");
    }
    

    This assumes that the report knows where to get its data from. Manually providing data requries additional steps.