How to use FastReport .NET with ASP .NET Web API

ASP.NET Web API reports may be created using the reporting tool FastReport.NET. The following are the steps to utilise FastReport.NET with the ASP.NET Web API:

  1. Install FastReport .NET – Installing the FastReport.NET library is required before using it with the ASP.NET Web API. Follow the installation instructions after downloading it from the official website.
  2. Create a new Web API project -In Visual Studio, start a new ASP.NET Web API project. You may use this to construct a default Web API project as a starting point.
  3. Add FastReport .NET to the project -Once a new Web API project has been made, FastReport.NET must be added to the project. You have two options for accomplishing this: either manually adding the FastReport.NET library to your project or using the NuGet Package Manager.
  4. Create a report -By choosing “File” > “New” > “Report” in FastReport.NET, you may create a new report. After a report has been prepared, it may be formatted, customised, and expanded upon as needed.
  5. Add a report viewer to the Web API project -You must include a report viewer in the project in order to display the report in the Web API. The FastReport.NET viewer control may be used for this. A new or existing ASP.NET Web Form or MVC view can have the viewer control added to it.
  6. Generate the report – You must add code to the Web API project that calls the report and sends it to the client in order to build the report. The FastReport.NET API may be used to do this. Here’s an example of some code:
    public HttpResponseMessage GetReport()
        var report = new FastReport.Report();
        var stream = new MemoryStream();
        report.Export(new FastReport.Export.Pdf.PDFExport(), stream);
        stream.Position = 0;
        var result = new HttpResponseMessage(HttpStatusCode.OK);
        result.Content = new StreamContent(stream);
        result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
        return result;

    As seen above, the code loads a report from a file, gets it ready for export, and then exports it as a PDF file. After that, the client receives a response in the form of the generated PDF.

  7. Test the report -By launching the project and sending a request to the report URL after adding the code to the Web API project, you can test the report. You may use a web browser or a programme like Postman to access a report, for instance, if its URL is “http://localhost:1234/api/report”.

In conclusion, installing the library, establishing a Web API project, adding the FastReport.NET library to the project, writing a report, adding a report reader to the project, and generating the report using the FastReport.NET API are all required in order to use FastReport.NET with ASP.NET Web API.

Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories