FlexReport supports azure deployment on Windows and can be used in Web API’s for exporting reports. Let us explore how to deploy FlexReport on Azure Windows Environment.
In this tutorial, we are deploying FlexReport on Azure Windows Environment to export it to Pdf.
Create a Web API project, add FlexReport and export it to PDF by performing the following steps:
<UseWindowsForms>true</UseWindowsForms>
Index.cshtml |
Copy Code
|
---|---|
<div class="text-center"> <h1 class="display-4">Welcome</h1> <p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p> </div> <a href="/Home/Export">Export PDF</a> |
HomeController.cs |
Copy Code
|
---|---|
public IActionResult Export() { try { //get Report path var path = Path.Combine(Directory.GetCurrentDirectory(), @ "wwwroot\files", "TestReport.flxr"); var reportName = "Test"; if (!System.IO.File.Exists(path)) { return Content("Unable to fnd Reprt"); } C1FlexReport report = new C1FlexReport(); report.Load(path, reportName); report.Render(); //Create PdfFilter object var stream = new MemoryStream(); //using (var stream = new MemoryStream()) { PdfFilter filter = new PdfFilter(); filter.ShowOptions = false; filter.Stream = stream; report.RenderToFilter(filter); stream.Position = 0; return File(stream, "application/pdf"); } } catch (Exception ex) { //Show Error message on screen return Content($"For {ex.Source} => {ex.Message} \n {ex.StackTrace}"); } } |
Follow these steps to create your App Service resources and publish your project to Azure Windows Environment platform:
Note: Azure support in the FlexReport API has been added for the Windows environment only so it cannot be hosted on any other environment.