Skip to main content

PageInfoDataProviderBase Class

A service that allows the XRPageInfo control to display custom information.

Namespace: DevExpress.XtraPrinting

Assembly: DevExpress.Printing.v23.2.Core.dll

NuGet Package: DevExpress.Printing.Core

Declaration

public abstract class PageInfoDataProviderBase

Remarks

The following code displays the name of a logged in user instead of a user under whose account the web server runs. The PageInfoDataProviderBase service processes the PageInfo bricks, and returns information from the HttpContext about the current user.

using System.Web;
using DevExpress.XtraPrinting;

class CustomPageInfoDataProvider : PageInfoDataProviderBase
{
    readonly HttpContext httpContext;
    public CustomPageInfoDataProvider(HttpContext httpContext)
    {
        this.httpContext = httpContext;
    }

    public override string GetText(PrintingSystemBase ps, PageInfoTextBrickBase brick)
    {
        if (brick.PageInfo != PageInfo.UserName)
        {
            return null;
        }
        if (httpContext == null)
            return "<No Information>";
        var user = httpContext.User;
        if (user == null || user.Identity == null)
            return "<Please enable Forms or Windows security>";
        var identity = user.Identity;
        return identity.IsAuthenticated
            ? identity.Name
            : "<Guest>";
    }
}

To add the custom page info data provider to a report’s Printing System, call the PrintingSystemBase.AddService method in the WebDocumentViewerOperationLogger.BuildStarting method body of a custom WebDocumentViewerOperationLogger implementation.

using System;
using System.Web;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Web.WebDocumentViewer;

class CustomWebDocumentViewerOperationLogger : WebDocumentViewerOperationLogger
{
    public override Action BuildStarting(string reportId, XtraReport report, ReportBuildProperties buildProperties)
    {
        var httpContext = HttpContext.Current;
        return () => GenerateBuildStatingAction(report, httpContext);
    }

    static void GenerateBuildStatingAction(XtraReport report, HttpContext httpContext)
    {
        report.PrintingSystem.AddService(typeof(PageInfoDataProviderBase), new CustomPageInfoDataProvider(httpContext));
    }
}

To configure a report before document creation, add the custom operation logger to the DefaultWebDocumentViewerContainer at application startup.

using DevExpress.Web.Mvc;
using WebDocumentViewer_UserName.Services;
using DevExpress.XtraReports.Web.WebDocumentViewer;
// ...
        protected void Application_Start() {
        // ...
            DefaultWebDocumentViewerContainer.RegisterSingleton<WebDocumentViewerOperationLogger, CustomWebDocumentViewerOperationLogger>();
            DefaultWebDocumentViewerContainer.DisableCachedDocumentSource();
            // ...
        }

View Example: How to Display the Name of the Current Logged in User in a Report

Inheritance

Object
PageInfoDataProviderBase
See Also