Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

How to: Execute Custom Code when a Report is Persisted

  • 2 minutes to read

This topic describes how you can customize the ReportsStorage class. Assume you have a customized the ReportDataV2 class and added the ModifiedBy property that should return the name of the user who last edited the report layout. You need to update this property value each time a report layout is saved. For this purpose, customize the ReportsStorage and register your custom implementation. The steps below demonstrate how to do it.

  • Inherit the ReportsStorage class and override its ReportsStorage.SaveReport method.

    using DevExpress.XtraReports.UI;
    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.ReportsV2;
    using DevExpress.ExpressApp.Security;
    // ...
    public class CustomReportsStorage : ReportsStorage {
        public override void SaveReport(IReportDataV2Writable reportData, XtraReport report) {
            if (reportData is MyReportDataV2) {
                ISecurityUser currentUser = SecuritySystem.CurrentUser as ISecurityUser;
                if (currentUser != null) {
                    ((MyReportDataV2)reportData).ModifiedBy = currentUser.UserName;
                }
            }
            base.SaveReport(reportData, report);
        }
    }
    
  • Edit the Module.cs (Module.vb) file and override the ModuleBase.Setup method. In this method, assign an instance of the CustomReportsStorage to the static ReportDataProvider.ReportsStorage property.

    using DevExpress.ExpressApp.ReportsV2;
    // ...
    public override void Setup(XafApplication application) {
        ReportDataProvider.ReportsStorage = new CustomReportsStorage();
        base.Setup(application);
    }