Exporting and Printing a Report from Code
Our sample projects and report templates can help you learn the basics of working with our products.You do not always need the viewer — in an ASP.NET Core app a report can be printed or exported straight to the HTTP response. Each action loads the report and returns it in a format.
Load the report, then respond in a format.
How it works. The loaded report is format-agnostic, so each controller action just picks how to serialize the same document — no viewer required.
Load the report, then respond in a format.
private StiReport GetReport()
{
var report = new StiReport();
report.Load(StiNetCoreHelper.MapPath(this, "Reports/TwoSimpleLists.mrt"));
return report;
}
public IActionResult ExportPdf() => StiNetCoreReportResponse.ResponseAsPdf(GetReport());
public IActionResult ExportXls() => StiNetCoreReportResponse.ResponseAsXls(GetReport());
public IActionResult PrintPdf() => StiNetCoreReportResponse.PrintAsPdf(GetReport());StiNetCoreReportResponse.ResponseAsPdf/ResponseAsHtml/ResponseAsXls— stream the report to the browser in that format.PrintAsPdf/PrintAsHtml— send it straight to the browser's print flow.
How it works. The loaded report is format-agnostic, so each controller action just picks how to serialize the same document — no viewer required.