Skip to main content

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.v23.2.Web.dll

NuGet Package: DevExpress.Web.Reporting.Common

Declaration

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

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);
        }
}

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:

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);
    }
}

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:

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

protected void Application_Start(object sender, System.EventArgs e) {
    // ...
    DefaultWebDocumentViewerContainer.RegisterSingleton<WebDocumentViewerOperationLogger, MyOperationLogger>();
}

Online Examples

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

View Example: How to implement a custom authorization service

View Example: Web Reporting - How to Manage Events of a Cached Document and Pass Custom Data to the Exported Document

Inheritance

Object
WebDocumentViewerOperationLogger
See Also