C# – using Crystal Reports ReportDocument

ccrystal-reports

I recently started using the latest version of Crystal Reports with both Visual Studio 2010 and SharpDevelop in a c# windows application (forms). I've downloaded the latest Crystal DLLs for Visual Studio 2010 from SAP and manually created references to the following

using CrystalDecisions.CrystalReports;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportSource;

I then create a ReportDocument so that I can open a rpt file:

ReportDocument rptDoc = new ReportDocument();

this all compiles fine. The problem arises when I try to use the rtpDoc object to do anything;

rptDoc.Load(@"c:\DialLeadsByDistributor.rpt");

it's as if the compiler doesn't realize it's a class object, despite the fact that when I mouse over the variable it reports it properly as a CrystalDecisions.CrystalReports.Engine.ReportDocument, but not only does intellisense not show me any methods or properties of the object, I get the following compiler error which has me stumped:

Invalid token '(' in class, struct, or interface member declaration

which references the above statement as the offending line…

Can anyone shed any light on this? If I look at the metadata for the ReportDocument class is does contain three Load methods, the first of which takes a string which is the rpt file path. The fact that this problem occurs in both Visual Studio 2010 and SharpDevelop is at least consistent, but still makes no sense to me.

Best Answer

try this code...it works both in VS2010 and sharpdevelop4:

using System;
using System.Drawing;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Windows.Forms;

namespace myapp
{

public partial class tstfrm1 : Form
{
    public tstfrm1()
    {

        InitializeComponent();

        ReportDocument rptDoc = new ReportDocument();
        rptDoc.Load(@"C:\CrystalReport1.rpt");
        /*If you have a datasource, link it like below*/
        //rptDoc.SetDataSource(dataset.Tables["tripsheet"]);
        CrystalReportViewer crystalReportViewer1 = new CrystalReportViewer();
        crystalReportViewer1.ReportSource = rptDoc;
        crystalReportViewer1.Refresh(); 
        this.Controls.Add(crystalReportViewer1);
        crystalReportViewer1.Dock = DockStyle.Fill;
    }
}

}

Related Topic