# Deployment

Get started with, FlexReport comprehensive reporting tool that provides complete reporting solution - from building complex reports to previewing, exporting, and printing.

## Content



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 Web API project and Export PDF

Create a Web API project, add FlexReport and export it to PDF by performing the following steps:

1.  Create a new Web API project in Visual Studio by selecting the **NET Core Web App [Model-View-Controller\]** template.<br />![](https://cdn.mescius.io/document-site-files/images/fd2ea167-30cb-4938-9938-b740a5b4dd95/images/webapi-template.png)<br />
2.  Setup a basic Web API project with the following given configurations.<br />![](https://cdn.mescius.io/document-site-files/images/fd2ea167-30cb-4938-9938-b740a5b4dd95/images/webapi-config.png)<br />![](https://cdn.mescius.io/document-site-files/images/fd2ea167-30cb-4938-9938-b740a5b4dd95/images/webapi-config-mvc.png)<br />
3.  Right-click on the Project file, click **Edit Project File** option and add the following lines in the \<PropertyGroup>\</PropertyGroup> tag.<br />`<UseWindowsForms>true</UseWindowsForms>`
    
    ![](https://cdn.mescius.io/document-site-files/images/fd2ea167-30cb-4938-9938-b740a5b4dd95/images/webapi-edit.png)
    
    <br />
4.  Open the project properties and set the **Target OS** to **Windows**.<br />![](https://cdn.mescius.io/document-site-files/images/fd2ea167-30cb-4938-9938-b740a5b4dd95/images/webapi-window.png)<br />Observe that the basic application setup is done.<br />
5.  Add the following FlexReport dependencies (NuGet package) to the project.
    *   C1.Win.FlexReport<br />
6.  Open **Views | Home | Index.cshtml** and add the following code to insert a link to export a PDF document via FlexReport.
    
    ```razor
    <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>
    ```
    
    <br />
7.  Add the report (\*.flxr) file in **wwwroot | files** folder of the project and add export endpoint in the **HomeController.cs** class as given in code below.
    
    ```csharp
    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}");
      }
    }
    ```
    
    <br />Observe that the export functionality is added to the WebAPI project and the App works as showcased in the following GIF. Here, on clicking the Export PDF hyperlink, it generates the report in PDF format on the server side and gets downloaded at client-side.<br />![](https://cdn.mescius.io/document-site-files/images/fd2ea167-30cb-4938-9938-b740a5b4dd95/images/webapi-app.gif)<br />

## Create App Service Resources

Follow these steps to create your App Service resources and publish your project to Azure Windows Environment platform:

1.  In the **Solution Explorer**, right-click the project name, and select **Publish**.<br />![](https://cdn.mescius.io/document-site-files/images/fd2ea167-30cb-4938-9938-b740a5b4dd95/images/webapi-publish.png)<br />
2.  In **Publish** window, select **Azure** and click **Next**.<br />![](https://cdn.mescius.io/document-site-files/images/fd2ea167-30cb-4938-9938-b740a5b4dd95/images/webapi-publishwindow.png)<br />
3.  Select **Azure App Service (Windows)** azure service. Then, click **Next**.<br />![](https://cdn.mescius.io/document-site-files/images/fd2ea167-30cb-4938-9938-b740a5b4dd95/images/webapi-azureservice.png)<br />
4.  Select your subscription name and click on create new instance.<br />![](https://cdn.mescius.io/document-site-files/images/fd2ea167-30cb-4938-9938-b740a5b4dd95/images/webapi-azuresignin.png)<br />In this step, you can select either add an account or sign in to sign into your Azure subscription. This depends on whether you are already signed into Azure and have a Visual Studio account linked to an Azure account. If you're already signed in, select the account you want.<br />
5.  Create a new instance and provide a unique app name in the **Name** field that includes only the valid characters (a-z, A-Z, 0-9, and -). Here, you can also accept the automatically generated unique name. The URL of the web app is **http://\<app-name>.azurewebsites.net**, where \<app-name> is your app name and click **Create**.<br />![](https://cdn.mescius.io/document-site-files/images/fd2ea167-30cb-4938-9938-b740a5b4dd95/images/webapi-azureapp.png)<br />Once the wizard completes, the Azure resources are created and the project is ready to be published.<br />
6.  Click **Finish** to complete the deployments.<br />![](https://cdn.mescius.io/document-site-files/images/fd2ea167-30cb-4938-9938-b740a5b4dd95/images/webapi-azureresource.png)<br />
7.  Change the Deployment Configuration as shown below:<br />![](https://cdn.mescius.io/document-site-files/images/fd2ea167-30cb-4938-9938-b740a5b4dd95/images/webapi-deploy.png)<br />![](https://cdn.mescius.io/document-site-files/images/fd2ea167-30cb-4938-9938-b740a5b4dd95/images/webapi-deployconfig.png)
8.  In the **Publish** page, select **Publish**.<br />![](https://cdn.mescius.io/document-site-files/images/fd2ea167-30cb-4938-9938-b740a5b4dd95/images/webapi-publishazure.png)<br />Visual Studio builds, packages, and publishes the app to Azure, and then launches the app in the default browser. Once all the steps are followed, the website is deployed on Azure.<br />

**Note**: Azure support in the FlexReport API has been added for the Windows environment only so it cannot be hosted on any other environment.