Hossein Gholamali
Hossein Gholamali

Reputation: 74

How to use stimulsoft in .NET6?

I want to use stimulsoft in a project written in ASP.NET MVC .Net6. StimulSoft version is 2022.1.1 and I installed NuGet

Stimulsoft.Reports.Web.NetCore

in my project.

Controller:

    ...
    public IActionResult PrintPage()
    {
        return View();
    }

    public IActionResult GetReport()
    {
        StiReport report = new StiReport();
        report.Load(StiNetCoreHelper.MapPath(this, "wwwroot/Reports/sample1.mrt"));
        var list = _unitOfWork.RefereeTypeRepos.GetAll(); //Get information for print.
        report.RegData("DT", list);
        return StiNetCoreViewer.GetReportResult(this, report);
    }

    public IActionResult ViewerEvent()
    {
        return StiNetCoreViewer.ViewerEventResult(this);
    }

PrintPage.cshtml:

    @using Stimulsoft.Report.Mvc
    @using Stimulsoft.Report.Web
    @Html.StiNetCoreViewer(new StiNetCoreViewerOptions()
    {
        Actions =
        {
            GetReport = "GetReport",
            ViewerEvent = "ViewerEvent"
        }
    })

When the page loads, I get this Error: enter image description here

I don't know what I should do, and which version or NuGet is proper for .Net6? I appreciate somebody answers.

Upvotes: -1

Views: 1471

Answers (1)

user20437316
user20437316

Reputation: 26

It works for me:

public IActionResult GetReport()
    {
        var person = new { Name = "samplename", Family = "samplefamily" };
        StiReport report = new StiReport();

        var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
        report.Load(path + "\\Reports\\Ticket.mrt");

        var service = new Stimulsoft.Report.Export.StiPdfExportService();

        report.RegData("PersonDetail", person);
        
        report.Render(false);

        StiPdfExportSettings st = new StiPdfExportSettings();
        st.ImageQuality = 1f;
        st.EmbeddedFonts = true;
        st.ImageResolution = 300;
        st.ImageFormat = StiImageFormat.Color;
        st.AllowEditable = StiPdfAllowEditable.No;

        var stream = new MemoryStream();
        // Export PDF using MemoryStream.
        service.ExportTo(report, stream, st);

        Response.Headers.Add("Content-Disposition", "attachment;filename=card.pdf");
        return File(stream.ToArray(), "application/pdf");
    }

It creates a pdf file and I use Nuget: stimulsoft.reports.engine.netcore

and there is no need for ViewerEvent() and PrintPage.cshtml

Upvotes: 1

Related Questions