xtrareports-404848-web-reporting-blazor-reporting-web-document-viewer-get-started-get-started-blazor-server.md
This tutorial adds the Document Viewer control (DxDocumentViewer) to a Blazor Web App (Interactive Server) template.
This section describes how to create a new Blazor project. If you want to start this tutorial using an existing application, go to Step 2.
Click Create a new project on Visual Studio’s start page and select the Blazor Web App template. Select Server from the Interactive Render Mode drop-down list.
Specify the project name and location, and click Next.
Specify additional options and click Create.
For additional information on available Blazor templates, refer to the following topic: Tooling for ASP.NET Core Blazor.
Install NuGet packages for Blazor Reporting:
Select Tools → NuGet Package Manager → Manage NuGet Packages for Solution.
In the invoked dialog, open the Browse tab, and install the following NuGet packages:
Build the project.
Refer to the following topic for more information: Install NuGet Packages in Visual Studio, VS Code, and Rider.
Register the services required for Blazor Reporting, and specify endpoint routing. For this, call the following methods in the Program.cs file:
Register DevExpress.Blazor and DevExpress.Blazor.Reporting namespaces in the _Imports.razor file:
In the App.razor file, call the RegisterScripts(Action<ResourcesConfigurator>) method to register DevExpress client resources:
If you pass a report name to a method that opens a report, you must implement and register one of the following services (to resolve report names):
IReportProviderA recommended service for the Document Viewer and Report Designer. The primary advantage of IReportProvider service is that it can be attached to reports created at runtime. IReportProviderAsync uses asynchronous operations.ReportStorageWebExtensionThis service is called when no other report name resolution services are available. It is designed to obtain reports (stored in our REPX format) from external storage (a file or a database). Note that the GetData method returns a serialized report. If you use the GetData method to specify the default parameter value for a loaded report, set the Value property to the parameter value.
In this example, we implement the IReportProvider service to load reports from the Reports folder in the project directory:
Create a MyReportProvider.cs file in the Services folder with the following code:
Register the MyReportProvider service in the Program.cs file:
Add a new Reports folder to a project. The folder name is specified in the IReportProvider implementation.
To perform this step, you should install DevExpress Reporting v25.2 on your machine. Refer to the following topic for more information: Run the Installation Wizard - DevExpress Unified Component Installer.
Select Project -> Add New Item… to invoke the Add New Item dialog. Navigate to the Reporting node and select the DevExpress v.25.2 Report item template.
Select Blank in the invoked Report Wizard page and click Finish.
Modify the newly created report in the Visual Studio Report Designer. Add a label and type Hello, World!:
Click the report’s smart tag and select Save… :
Create a new razor file (DocumentViewer.razor) in the Pages folder. Use the code below to generate a page with a Document Viewer component.
Enable interactivity for DevExpress components:
Make sure the required interactive services are registered.
Add an appropriate render mode attribute to a component’s page.
@page "/documentviewer"
@rendermode InteractiveServer
<DxDocumentViewer ReportName="TestReport" Height="1000px" Width="100%">
<DxDocumentViewerTabPanelSettings Width="340" />
</DxDocumentViewer>
The DxDocumentViewer component loads the TestReport report to create a document.
Add navigation links to the NavMenu.razor page:
<div class="nav-item px-3">
<NavLink class="nav-link" href="documentviewer">
<span class="oi oi-list-rich" aria-hidden="true"></span> Document Viewer
</NavLink>
</div>
Run the project. The Document Viewer loads the TestReport.repx report:
Restore Data ConnectionsLearn how to implement a service that restores data connections for data-aware reports loaded in the Document Viewer.Specify Report Parameters Learn how to specify report parameters using the built-in Parameters Panel or create custom UI elements and use them to submit parameter values to the report.Handle Client-Side EventsLearn how to handle client-side events raised by the JavaScript-based Document Viewer.Customize Parameter EditorsLearn how to customize built-in parameter editors in the JavaScript-based Document Viewer.Customize the Tab PanelLearn how to customize the Document Viewer Tab Panel.Customize the ToolbarLearn how to customize the Document Viewer Toolbar.TroubleshootingThis topic lists common issues that can occur in a Web Reporting application and describes solutions. For information on how to identify the cause of an issue, refer to the following help topic: Reporting Application Diagnostics.