How to upload report into Online Designer and download edited report
One of the first questions that faces Online Designer users is how to organize downloading reports from a local computer? Today we will consider uploading from the local computer to Online Designer and downloading the modified report using the example of the ASP.Net MVC application.
Create an ASP.Net MVC project. We will need the following libraries:
Open the controller HomeController.cs. Add the missing libraries to the uses section:
We will display OnlineDesigner in the Index method. But, first we create a web report object and a cache for storing the report file. I use the cache in order to avoid saving the file on the server:
Method for obtaining the path to the reports:
Next, we add the method of uploading the file:
Note the DateTimeOffset.Now.AddMinutes (1) parameter. It specifies the cache lifetime.
Now we need a method of saving the report in Online Designer:
We create a single view SaveDesignedReport.cshtml for this method:
It remains to implement the method of downloading the report file:
Now consider the view for the Index page (Home-> Index.cshtml):
At the top we display the title of the page. Next, use the BeginForm helper to create a form with a file select button. The parameters specify the name of the handler method - "Upload", the controller name is "Home", the processing method is FormMethod.Post, the data encoding method is - enctype = "multipart/form-data".
Next, insert the file download field and the button.
On the right side of the page, we'll place one more button on which the edited report will be downloaded. For it, we also create a form using the BeginForm helper.
In the last line of code, we display the report received from the controller.
It is necessary to connect the scripts in the file _Layout.cshtml:
Now you need to make changes to the two web configs. The files are called the same, but they are located in different folders. The first one is located in the Views folder. We add to it:
The second file is located at the root of the project. In it we add a handler:
Run our application.
We see OnlineDesigner with an empty report. Download the report from the local computer using the "Select file" button. From the dialog box, select the file and click the Upload button:
The report template was loaded. Let's change the background color in the data band. On the "Report" tab, we click the "Save" button:
The SaveDesignedReport method works and we see the green alert on the right:
Now click the «Download designed report» button:
Browser download our report. Open it with Report Designer:
And get our report, edited with Online Designer.