While working with FastReports online report designer, we usually have to upload our report templates into it, and then, after editing, download them. Today we will look at how this can be done in the context of an ASP.Net Core application.
Create an ASP.Net Core application. Add the FastReport.Net libraries to it using NuGet. Use the local package source - the Nuget folder from the FastReport.Net installation directory. Install two packages FastReport.Core and FastReport.Web.
Add the App_Date folder to the wwwroot folder. Put the data source for the demo reports in it - nwind.xml.
We also add a folder with an online designer in wwwroot, which you downloaded from the official website www.fast-report.com .
To use the FastReports libraries in your project, you must add one line to the Startup.cs file:
Let's proceed to editing the HomeController controller.
We need to create 4 methods: display the report designer with the loaded report, upload the file to the server, generate a file for downloading, save the modified report to the server.
When displaying a web page, at first you will see a report designer with a blank template. And after uploading the report file to the server, the designer will appear with the template loaded.
Notice that we use ViewData to pass the report name to the view.
Now change the view for the Index method:
Here we used two ways to send requests to the server - through the form and through the ajax request. In the first case, we load the file, and since we still need to update the report designer, we can neglect to refresh the entire page. In the second case, when downloading the report file, we do not want to refresh the page and it is better to use the ajax request. We cannot organize file downloading with only ajax request, therefore when processing the result of the request we create a tag with a link to the file being downloaded.
For the SaveDesignedReport method in the controller, you need to create a view with the code:
That's all. Run the application. First we see a report designer with an empty template.
Click the button "Select file" and select the report template to download.
Press the button "Upload file":
And we get a report designer with a loaded template. We can perform any manipulations with the template and save it. And then, click the "Download Report" button.
And the browser loads the report file.
Thus, we realized our plans - a full-fledged report editor with the ability to load, save and download a report.