For getting Pdf report in Asp.net MVC I am working with Stimulsoft 2015. The problem is that I have no idea how to convert my code in order to work with Stimulsoft Core in Asp.net Core. it seems some features are not available anymore in Stimulsoft Core (like StiReport).
This is the code which works fine in Asp.net MVC
public ActionResult GetReportSnapshot(string sort)
{
StiReport report = new StiReport();
report.Load(Server.MapPath("~/Reports/Jobs.mrt"));
report["@PrjectId"] = 1;
report["@OrderBy"] = sort;
report.Dictionary.Variables["title"] = new Stimulsoft.Report.Dictionary.StiVariable("title", sort);
report.Render();
MemoryStream stream = new MemoryStream();
report.ExportDocument(StiExportFormat.Pdf, stream);
stream.Position = 0;
FileStreamResult fsr = new FileStreamResult(stream, "application/pdf");
return fsr;
}
I will appreciate any help.
What nuget packages are you using? It could be you are missing the nuget packages containing the StiReport
class. (I see they split up their library over multiple nuget packages)
Also it could be they have not migrated this part to dotnet core yet. i'd advise you to click around there github repo and see if you can find any information there: https://github.com/stimulsoft, or on there website.
By the looks of nuget they have only recently started to migrate to dotnet core so this would suppose my second suggestion is the right suggestion.
In NuGet Package Stimulsoft.Reports.Web.NetCore
version 2018.3.5
.
and Asp.Net core 2.0
.
This is working for me, Try this:
public IActionResult GetReportSnapshot(string sort)
{
StiReport report = new StiReport();
report.Load(@"C:\Users\Admin\Desktop\report.mrt"); // laod report
report.Render();
report["@PrjectId"] = 1;
report["@OrderBy"] = sort;
report.Dictionary.Variables["title"] = new Stimulsoft.Report.Dictionary.StiVariable("title", sort);
// Create an PDF settings instance. You can change export settings.
var settings = new Stimulsoft.Report.Export.StiPdfExportSettings();
// Create an PDF service instance.
var service = new Stimulsoft.Report.Export.StiPdfExportService();
// Create a MemoryStream object.
var stream = new MemoryStream();
// Export PDF using MemoryStream.
service.ExportTo(report, stream, settings);
return File(stream.ToArray(), "application/octet-stream");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With