Link to home
Start Free TrialLog in
Avatar of mike8758
mike8758

asked on

running a crysal report from a console application

Hi,  I am working on a console application that has a crystal report attached to it as part of its project.  I am trying to find a way to trigger the report from within the console application and output the report to a file to be used later.  The report is connected to a SQL database table on a remote server.  The code that I have been attempting to use so far is just&

       ReportDocument billrpt = new ReportDocument();
       rpt.Load("~/Report.rpt");

When it runs I get a load report failed error.  I am assuming there has to be more to setting this up.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mike8758
mike8758

ASKER

I wanted to add a little clification to this item because even though emoreau pointed out my problem the total solution was not reported.

This turned out to be much easier then I had though

In my console application I ran the following snipet&

ReportDocument rpt = new ReportDocument();
string apppath = Application.StartupPath.ToString() + "\\Report.rpt";
rpt.Load(apppath);
rpt.SetDatabaseLogon("user","password");
rpt.ExportToDisk(ExportFormatType.PortableDocFormat, c:\\testreport.pdf");

Now some things to keep in mind&
1:  In my case my report was an added item to my console application project.
2:  And my (crystal) report was set up to use dedicated database tables that are loaded by my console app earlier in the process.