views:

1685

answers:

3

Is it possible for a stand alone executable to generate a report and output it as PDF (or one of the other export options available from the report viewer) without displaying the ReportViewer control?

The report definition should be embedded in the executable and should not use the Reporting Services web service.

+3  A: 

You don't have to show the control itself.

ReportViewer rv = new ReportViewer();
rv.LocalReport.ReportPath = "templatepath";
// or use file from resource with rv.LocalReport.ReportEmbeddedResource

// add parameters, datasource, etc.

Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string filenameExtension;

byte[] bytes;
bytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);

// save byte[] to file with FileStream or something else

However it can render only PDF and XLS (as ReportViewer control cannot export to Word and others as Reportig Service can).

I forgot to mention that the above code is C#, using .NET framework and ReportViewer control. Check out GotReportViewer for a quickstart.

Biri
For the record, the format used to render as Excel is "Excel" rather than "XLS".
flipdoubt
+6  A: 

Actually you don't need a ReportViewer at all, you can directly instantiate and use a LocalReport:

LocalReport report = new LocalReport();
report.ReportPath = "templatepath";
// or use file from resource with report.ReportEmbeddedResource

// add parameters, datasource, etc.

Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string filenameExtension;

byte[] bytes;
bytes =report.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);

// save byte[] to file with FileStream or something else
csgero
A: 

Can you pass a .rdlc report directly to pdf with parameters? I have two dropdownlists that i pull my report with. I can't get the parameters to work when automatically exporting to pdf. Here is the error I get: Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: One or more parameters required to run the report have not been specified.

The dropdownlists work when I use the reportviewer, but i want to skip this step. I can also get my data to go directly to a pdf if it doesn't have any parameters. My dropdownlists are called ddlyear and ddlmonth.