Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migirating to Stimulsoft Core

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.

like image 702
Elyas Esna Avatar asked Oct 29 '22 10:10

Elyas Esna


2 Answers

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. enter image description here

like image 154
Joel Harkes Avatar answered Jan 02 '23 20:01

Joel Harkes


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");
        }
like image 29
AminRostami Avatar answered Jan 02 '23 19:01

AminRostami