I'm working in a ASP.net core 3.1 web application. I want to display a Report without using the report viewer as well as not embedding the datasource into the report. The data for the report will be determined at runtime. So this is what I have done so far.
Defined a report with the report designer that has just one field = Fields.Title
The report does render with the correct number of lines that I expected. However there is no data. The data object that gets assigned to the report datasource does have values. Five values from the database. It's just that the those values don't bind to the ["Fields.Title] property of the report. All I see is
Title
Title
Title
Title
Title
Here's the code
Controller Method that gets called from the GUI
public FileContentResult GetTasksReports()
{
return File(_reportService.GetTaskReport(), "application/pdf");
}
Service methods
public byte[] GetTaskReport()
{
//get data from db. This returns data
var tasks = _taskRepository.GetAllList();
//Populate a List of Classes that will serve as the Reports datasource
List<
MyTasks
> taskList = new List<
MyTasks
>();
foreach (Task t in tasks)
{
MyTasks ts = new MyTasks()
{
Title = t.Title
};
taskList.Add(ts);
};
return getReport(taskList, "TasksNoEmbeddedDS.trdp");
}
private byte[] getReport(dynamic ds, string telerikReportName)
{
string reportName = "Reports\\Tasks\\" + telerikReportName;
ReportPackager reportPackager = new ReportPackager();
Telerik.Reporting.Report report = null;
using (var sourceStream = System.IO.File.OpenRead(reportName))
{
report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
//assign the data to the Report Datasource
report.DataSource = ds;
}
return RenderMyReport(report);
}
private byte[] RenderMyReport(Telerik.Reporting.Report report)
{
System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
InstanceReportSource instanceReportSource = new InstanceReportSource()
{
ReportDocument = report
};
var configuration = ConfigurationHelper.ResolveConfiguration(webHostEnvironment);
ReportProcessor reportProcessor = new ReportProcessor(configuration);
RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo);
return result.DocumentBytes;
}
public class MyTasks
{
public string Title;
}