Using a Report Export Service
Our sample projects and report templates can help you learn the basics of working with our products.A report can be exposed as a web-API endpoint that renders and returns a document on demand — a lightweight export service.
Render on request and return the file. The API action picks the format from a query parameter:
How it works. Any client can request a rendered report by URL, so exporting becomes a service other applications call directly.
Render on request and return the file. The API action picks the format from a query parameter:
[HttpGet]
public IActionResult Get(string reportName, string format = "pdf")
{
var report = new StiReport();
report.Load(Path.Combine("Reports", reportName + ".mrt"));
report.Render(false);
var stream = new MemoryStream();
switch (format)
{
case "pdf":
report.ExportDocument(StiExportFormat.Pdf, stream);
return File(stream.ToArray(), "application/pdf");
case "excel":
report.ExportDocument(StiExportFormat.Excel2007, stream);
return File(stream.ToArray(), "application/vnd.ms-excel");
default:
return Content($"Format [{format}] is not supported!");
}
}[HttpGet] Get(reportName, format)— an API endpoint taking the template name and desired format.ExportDocument(format, stream)+File(bytes, mime)— render, then return the document with the right content type.
How it works. Any client can request a rendered report by URL, so exporting becomes a service other applications call directly.