0

I have written a report is C# using a CrystalReportForm. I wrote this as a Windows Forms Application. (Visual Studio 2015).It works well but I need to convert this to a console application so I can automate it.

I used the CrystalReportViewer and possibly this is not the best approach. Any assistance/direction is appreciated.

DSP = new Classes.DSP_Object(txtStartDate.Text);
var crf = new CrystalReportForm();
var dsp = new CrystalReports.DSP_Report();
((TextObject)dsp.ReportDefinition.Sections["Section1"].ReportObjects
["lblWeekOfHeader"]).Text = DSP.lblWeekOfHeader;
//Lots more assignments of object fields to report
    .
    .
    .
crf.crv1.ReportSource = dsp;
crf.Show();
//The report looks great at this point.         
Steve Cross
  • 89
  • 1
  • 13
  • Hi Steve, can you please add a code example of what you have tried and what exactly you are experiencing? A quick google search turned up quite a few results in tutorial format if that is what you need, and this forum is for finding specific answers to specific questions. – Nik P May 26 '20 at 18:43
  • What exactly you want to automate? Could you please elaborate? – zafar May 26 '20 at 18:44
  • I want to be able to run the console application to create the report. It works as is but a user has to run it. I want to be able to schedule it to be run. This CR is created in code and then the fields on the report are populated from the code. – Steve Cross May 28 '20 at 17:48
  • //Instantiate class DSP = new Classes.DSP_Object(txtStartDate.Text); //Create CR Objects var crf = new CrystalReportForm(); var dsp = new CrystalReports.DSP_Report(); ((TextObject)dsp.ReportDefinition.Sections["Section1"].ReportObjects["lblWeekOfHeader"]).Text = DSP.lblWeekOfHeader; //Lots more assignments of object fields to report . . . crf.crv1.ReportSource = dsp; crf.Show(); //The report looks great at this point. – Steve Cross May 28 '20 at 18:05
  • Well, that last comment is not formatted very well. Sorry. – Steve Cross May 28 '20 at 18:05

2 Answers2

0

Since you need to run it from a console application, I wouldn't attempt to host a viewer inside the console application - that's not going to work.

Instead, you can run the report from the console app, save as a pdf and show the pdf.

Once you generate the report, you can do something like this:

Process p=new Process();
p.StartInfo.FileName = @"G:\GeneratedCrystalReport.pdf";
p.Start();
HaroldP1
  • 31
  • 7
  • This sounds like the direction I need to move. I will want to email the report (PDF) after it is completed. It is the generation of the PDF that I could use some direction on. The report uses several fields from my code. It is not a stand alone CR. It works well in the CR viewer but I don't know how to move to the PDF from here. – Steve Cross May 28 '20 at 17:47
  • If you need export the `.rpt` as a PDF, see https://stackoverflow.com/a/17100836/3390788 – Frank Alvaro May 30 '20 at 13:18
0

This question shows my ignorance in Crystal with C#. It was an easy fix. Just had to load the document and not reference it through the viewer.

Steve Cross
  • 89
  • 1
  • 13