Back to Devexpress

WebDocumentViewerOperationLogger Class

xtrareports-devexpress-dot-xtrareports-dot-web-dot-webdocumentviewer-8d483727.md

latest8.1 KB
Original Source

WebDocumentViewerOperationLogger Class

A service that allows you to handle and log report processing and document generation events in the Web Document Viewer control.

Namespace : DevExpress.XtraReports.Web.WebDocumentViewer

Assembly : DevExpress.XtraReports.v25.2.Web.dll

NuGet Package : DevExpress.Web.Reporting.Common

Declaration

csharp
public class WebDocumentViewerOperationLogger
vb
Public Class WebDocumentViewerOperationLogger

Remarks

You can use a WebDocumentViewerOperationLogger class descendant to perform necessary actions at all stages of the Document Viewer lifecycle. You can modify the report and document settings, and execute custom code before a document is built, exported, or printed.

For this, create the WebDocumentViewerOperationLogger class descendant, override appropriate methods related to your task, and register the class as a service in your application.

Example: Log the Print Action

csharp
using DevExpress.XtraReports.Web.WebDocumentViewer;
using DevExpress.XtraPrinting;
using System;
// ...

public class MyOperationLogger : WebDocumentViewerOperationLogger {
        public override void ExportDocument(string documentId, string format, DevExpress.XtraPrinting.ExportOptions options, PrintingSystemBase printingSystem) {
            if (format == "printpdf") {
                // A customer clicked the "Print" or "Print Page" button
            }            
            base.ExportDocument(documentId, format, options, printingSystem);
        }
}
vb
Imports DevExpress.XtraReports.Web.WebDocumentViewer
Imports DevExpress.XtraPrinting
Imports System;
' ...

Public Class MyOperationLogger
    Inherits WebDocumentViewerOperationLogger
    Public Overrides Sub ExportDocument(documentId As String, format As String, options As ExportOptions, printingSystem As PrintingSystemBase)
        If format == "printpdf" Then
            ' A customer clicked the "Print" or "Print Page" button
        End If
        MyBase.ExportDocument(documentId, format, options, printingSystem)
    End Sub
End Class

Example: Prohibit Export to Any Format Except PDF

The following example restricts report export to any format except PDF. It demonstrates a server-side method that is preferable to a method that uses a client-side API in certain scenarios.

Override the ExportDocument method in the WebDocumentViewerOperationLogger descendant:

csharp
using DevExpress.XtraReports.Web.WebDocumentViewer;
using DevExpress.XtraPrinting;
using System;
// ...

public class MyOperationLogger : WebDocumentViewerOperationLogger {
    public override void ExportDocument(string documentId, string format, ExportOptions options, PrintingSystemBase printingSystem) {
        if (format != "pdf") {
            throw new NotSupportedException(String.Format("Export to {0} format is not allowed!", format.ToUpper()));
        }
        // Specify the default PDF export options.
        options.Pdf.Assign(new PdfExportOptions());
        base.ExportDocument(documentId, format, options, printingSystem);
    }
}
vb
Imports DevExpress.XtraReports.Web.WebDocumentViewer
Imports DevExpress.XtraPrinting
Imports System;
' ...

Public Class MyOperationLogger
    Inherits WebDocumentViewerOperationLogger
    Public Overrides Sub ExportDocument(documentId As String, format As String, options As ExportOptions, printingSystem As PrintingSystemBase)
        If format <> "pdf" Then
            Throw New NotSupportedException([String].Format("Export to {0} format is not allowed!", format.ToUpper()))
        End If
        ' Specify the default PDF export options.
        options.Pdf.Assign(New PdfExportOptions())
        MyBase.ExportDocument(documentId, format, options, printingSystem)
    End Sub
End Class

If you need to build report documents synchronously, override the BuildStarting method instead. This may be necessary when you need to access HttpContext in the report control’s BeforePrint event handler.

Register the Service

Register the MyOperationLogger service at application startup:

csharp
using DevExpress.XtraReports.Web.WebDocumentViewer;
// ...

protected void Application_Start(object sender, System.EventArgs e) {
    // ...
    DefaultWebDocumentViewerContainer.RegisterSingleton<WebDocumentViewerOperationLogger, MyOperationLogger>();
}
vb
Imports DevExpress.XtraReports.Web.WebDocumentViewer
' ...

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    DefaultWebDocumentViewerContainer.RegisterSingleton(Of WebDocumentViewerOperationLogger, MyOperationLogger)()
End Sub
cs
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSingleton<WebDocumentViewerOperationLogger, MyOperationLogger>();

var app = builder.Build();

Online Examples

View Example: Reporting for ASP.NET MVC - How to Display the Name of the Current Logged in User in a Report

View Example: Reporting for ASP.NET MVC - How to implement a custom authorization service

View Example: Reporting for ASP.NET Core How to Manage Events of a Cached Document and Pass Custom Data to the Exported Document

View Example: Reporting for ASP.NET MVC - How to Manage Events of a Cached Document and Pass Custom Data to the Exported Document

Inheritance

Object WebDocumentViewerOperationLogger

See Also

WebDocumentViewerOperationLogger Members

PageInfoDataProviderBase

IWebDocumentViewerAuthorizationService

Document Viewer Lifecycle

Register Services in the Document Viewer (ASP.NET Web Forms)

Register Services in the Document Viewer (ASP.NET MVC)

Register Services in the Document Viewer (ASP.NET Core)

DevExpress.XtraReports.Web.WebDocumentViewer Namespace