Search code examples
crystal-reports-xi

How to load rpt file using c# in visual studio 2010?


Am using visual studio 2010 and trying to load a rpt file. I have used the following code.

ReportDocument rpt = new ReportDocument();
rpt.Load("E:\\Crystal reports docs\\Crystal Reports samples\\Crosstab report");

Then I used isLoaded() function to check whether it is loaded.

When I compile the program, it keeps on running.

Any suggestions???

Thanks in advance!!!!


Solution

  • Here is the sample code how to load a crystal report (.rpt) file that is saved on a local drive instead of embedded. The advantage to this is the program does not need to be re-compiled each time a report is modified. Also, the .rpt can be upload from the application and stored in a database and then written to file. Do not embed the .rpt file when using this method.

    using System;using CrystalDecisions.CrystalReports.Engine;
    using CrystalDecisions.Shared;
    
    namespace Report
    {
        public partial class Report : Document    
        {
            public void ReportLoad()    
            {
                ReportDocument reportDocument = new ReportDocument();       
                string filePath = "C:\Projects\Application\Report\CrystalReport.rpt";                
                reportDocument.Load(filePath);  
                crystalReportViewer.ReportSource = reportDocument; 
            }   
        }
     }
    

    Refer More about

    http://scn.sap.com/thread/3312329

    How do I load external Crystal Reports (2008) files in c#?