Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
how to download jsreport without open using c# in .Net

I am Use JS Report for view. This code render the file and and Save in root directory. But I want file is directly download not open for view.

  var header = await _jsReportMVCService.RenderViewToStringAsync(HttpContext, RouteData, "Header", new { });
                var footer = await _jsReportMVCService.RenderViewToStringAsync(HttpContext, RouteData, "Footer", new { });
                HttpContext.JsReportFeature()
                     .Recipe(Recipe.ChromePdf)
                     .Configure((r) =>
                     {
                         //r.Options = new RenderOptions
                         //{
                         //    Timeout = 600000
                         //};
                         r.Template.Chrome = new Chrome
                         {
                             HeaderTemplate = header,
                             FooterTemplate = footer,
                             DisplayHeaderFooter = true,
                             MarginTop = "1cm",
                             MarginLeft = "2cm",
                             MarginBottom = "2cm",
                             MarginRight = "1.5cm",
                             Format = "A3"
                         };
                     });
                HttpContext.JsReportFeature().OnAfterRender((renderer) =>
                {
                    using (var file = System.IO.File.Open("EmployeesList.pdf", FileMode.Create))
                    {
                        renderer.Content.CopyTo(file);

                    }
                    renderer.Content.Seek(0, SeekOrigin.Begin);
                });
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can download a JSReport like this

[MiddlewareFilter(typeof(JsReportPipeline))]
public IActionResult InvoiceDownload()
{
            HttpContext.JsReportFeature().Recipe(Recipe.PhantomPdf)
                .OnAfterRender((r) => HttpContext.Response.Headers["Content-Disposition"] = "attachment; filename=\"myReport.pdf\"");

            return View("Invoice", InvoiceModel.Example());
}

You can get help from the official asp.net core example.

Hope this helps you

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!