Skip to main content

PageInfoDataProviderBase Class

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

Namespace: DevExpress.XtraPrinting

Assembly: DevExpress.Printing.v22.1.Core.dll

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

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the PageInfoDataProviderBase class.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

Inheritance

Object
PageInfoDataProviderBase
See Also