Progress® Telerik® Reporting R3 2019

Reference Report Definitions in Applications

The article elaborates on how to specify which report definition to be used by the report engine when rendering the report in an application.

Report Source

To specify and pass a report definition to the report engine it is required to use a wrapper in the form of a report source object. This wrapper contains information about how to fetch the report definition and what parameter values to use when the report is processed. It is important to know the different report source types and when/how to use them. Please refer to Report Sources for detailed information.

Reference Reports in Report Viewers

The report viewer is a UI component which is used to specify a report definition via a report source, send the report source for processing and rendering to the report engine, and then display the rendered report document in the application. Depending on the application type the report viewer can be communicating with a remote report engine via a service, or directly with a report engine embedded in the same application as the report viewer control. Regardless of this, the report to be displayed is specified by setting a report source property of the report viewer.

When working with an embedded report engine, the report source property accepts objects of the ReportSource type.

When working with a remote report engine via a service, the ReportSource type might not be available, especially in client-server scenarios where the report engine is hosted in a different application. In such scenarios an intermediate report source has to be described (JSON object, custom C# type, etc.). The service which is responsible for accessing the report engine will try to translate this intermediate report source to an actual ReportSource object.

For more details and examples on the different report sources, please refer to How to: Set ReportSource for Report Viewers.

Reference Reports in Report Processor

When the report engine is embedded in the current application (i.e. the Telerik.Reporting assembly is referenced) it is possible to use the Report Processor to manually render (RenderReport) or print (PrintReport) a report. For this purpose it is required to pass an argument of ReportSource type which uniquely identifies the report.

For this example we will use a TypeReportSource. The TypeReportSource specifies the report by its Assembly Qualified Name. The Reporting Engine uses Reflection to create an instance of the report class through its default parameterless constructor.

var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();

// set any deviceInfo settings if necessary
var deviceInfo = new System.Collections.Hashtable();

// Depending on the report definition choose ONE of the following REPORT SOURCES
//                  -1-
// ***CLR (CSharp) report definitions***
var reportSource = new Telerik.Reporting.TypeReportSource();

// reportName is the Assembly Qualified Name of the report
reportSource.TypeName = reportName;
//                  -1-

////                  -2-
//// ***Declarative (TRDP/TRDX) report definitions***
//var reportSource = new Telerik.Reporting.UriReportSource();

//// reportName is the path to the TRDP/TRDX file
//reportSource.Uri = reportName;
////                  -2-

////                  -3-
//// ***Instance of the report definition***
//var reportSource = new Telerik.Reporting.InstanceReportSource();

//// Report1 is the class of the report. It should inherit Telerik.Reporting.Report class
//reportSource.ReportDocument = new Report1();
////                  -3-

// Pass parameter value with the Report Source if necessary
object parameterValue = "Some Parameter Value";
reportSource.Parameters.Add("ParameterName", parameterValue);

Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("PDF", reportSource, deviceInfo);

string fileName = result.DocumentName + "." + result.Extension;
string path = System.IO.Path.GetTempPath();
string filePath = System.IO.Path.Combine(path, fileName);

using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
{
    fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
}

See Also

Other Resources

In this article
Not finding the help you need?