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.
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;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With