Skip to main content
All docs
V25.1
  • Migrate ASPxWebDocumentViewer from Web Forms to ASP.NET Blazor

    • 4 minutes to read

    You can migrate ASPxWebDocumentViewer customization to a new .NET application. The component uses HTML/JavaScript and shares core functionality across different web frameworks - the client-side API is the same regardless of the platform, allowing you to migrate the customization code to a new app with minimal adjustments. The custom implementation of Document Viewer’s services can also be migrated to a new application because interface implementation is similar in all web frameworks.

    Prerequisites

    You may require additional packages to run our Reporting components on Linux or iOS: Use Reporting on Linux.

    Important

    In .NET 8, the System.Drawing.Common library is compatible with Windows only. An exception is thrown on other platforms. See the following topic for more information: Reporting .NET/.NET Core Limitations.

    Create an ASP.NET Blazor Application

    Create a new ASP.NET Blazor Server App. Use Visual Studio or the .NET CLI to create a new project:

    dotnet new blazor -o AspNetBlazorDocumentViewer
    

    Install the DevExpress NuGet Packages

    Install NuGet packages for Blazor Reporting:

    1. Select ToolsNuGet Package ManagerManage NuGet Packages for Solution.

    2. In the invoked dialog, open the Browse tab, and install the following NuGet packages:

      • DevExpress.Blazor.Reporting.JSBasedControls
      • DevExpress.AspNetCore.Reporting

      The DevExpress 25.1 Local package is automatically added as a package source to your NuGet configuration files if you used the DevExpress .NET Product Installer.

    3. Build the project.

    Configure Services on Startup (Program.cs)

    All Web Document Viewer services that you register in DefaultWebDocumentViewerContainer for ASP.NET Web Forms app can be registered in the built-in DI container in ASP.NET Blazor applications. You can parameterize and inject other services within the constructors of Document Viewer-specific services (for example, IHttpContextAccessor). You do not require to update the signature and definition of services that exist in your legacy ASP.NET Web Forms app. You can copy the implementation of your custom services to your new application as-is. Note that you can use the dependency-injection concept for all migrated services.

    The following code snippet registers the IWebDocumentViewerReportResolver service:

    ASP.NET Web Forms
    using DevExpress.XtraReports.Web.WebDocumentViewer;
    // ...
    void Application_Start(object sender, EventArgs e) {
        DefaultWebDocumentViewerContainer.Register<IWebDocumentViewerReportResolver, CustomWebDocumentViewerReportResolver>();
    // ...    
    }
    
    ASP.NET Blazor
    using DevExpress.XtraReports.Web.Extensions;
    // ...
    var builder = WebApplication.CreateBuilder(args);
    builder.Services.AddSingleton<IWebDocumentViewerReportResolver, CustomWebDocumentViewerReportResolver>();    
    // ... 
    var app = builder.Build();
    

    The following code snippet references services required by DevExpress Reporting:

    using DevExpress.Blazor.Reporting;
    using DevExpress.XtraReports.Web.Extensions;
    
    var builder = WebApplication.CreateBuilder(args);
    builder.Services.AddMvc();
    builder.Services.AddDevExpressBlazorReporting();
    // ...
    builder.Services.ConfigureReportingServices(configurator => {
        configurator.ConfigureWebDocumentViewer(viewerConfigurator => {
            viewerConfigurator.UseCachedReportSourceBuilder();
        });
    });
    
    var app = builder.Build();
    app.UseRouting();
    app.UseDevExpressBlazorReporting();
    app.UseDevExpressControls();
    app.UseEndpoints(endpoints => {
        endpoints.MapControllers();
    });
    
    app.Run();
    

    Add a Report

    The .cs and .repx reports are cross-platform and can be reused in any platform reporting application. Refer to the following topic for information on how to prepare reports for migration: Migrate DevExpress Reports to .NET Applications.

    Adjust Views

    The following code sample displays the Document Viewer and loads the TestReport:

    Web Forms Markup
    <asp:Content ID="Content" ContentPlaceHolderID="MainContent" runat="server">
        <dx:ASPxWebDocumentViewer ID="ASPxWebDocumentViewer1" runat="server" ReportSourceId="WebFormsExample.Reports.TestReport" >
        </dx:ASPxWebDocumentViewer>
    </asp:Content>
    
    ASP.NET Blazor View
    @page "/documentviewer"
    
    <DxDocumentViewer ReportName="TestReport" Height="calc(100vh - 130px)" Width="100%">
    </DxDocumentViewer>
    

    Migrate Client-Side Customization

    To handle Client-Side events use the DxDocumentViewerCallbacks object members. Check the following documentation for more details on how to use Client-Side API in ASP.NET Blazor application: Customization - Document Viewer for Blazor Server.

    Web Forms Markup
    <asp:Content ID="Content" ContentPlaceHolderID="MainContent" runat="server">
        <dx:ASPxWebDocumentViewer ID="ASPxWebDocumentViewer1" runat="server" ReportSourceId="WebFormsExample.Reports.TestReport" >
           <ClientSideEvents BeforeRender="onbeforeRender"/>
        </dx:ASPxWebDocumentViewer>
    </asp:Content>
    
    ASP.NET Blazor View
    @page "/documentviewer"
    
    <DxDocumentViewer ReportName="TestReport" Height="calc(100vh - 130px)" Width="100%">
        <DxDocumentViewerCallbacks BeforeRender="onBeforeRender"/>
    </DxDocumentViewer>
    

    Note some functionality specific for the ASP.NET Blazor platform:

    1. The Init event no longer exists in ASP.NET Blazor. You can rewrite your customization logic using the BeforeRender event.

    2. ASP.NET Blazor uses callbacks which have the only one handler. You cannot use subscription with the AddHandler method.