Skip to main content

Ensure Safe Loading of Reports (WinForms)

  • 2 minutes to read

This topic describes how to allow users to load only secure reports in WinForms reporting applications.

End-User Report Designer (WinForms and WPF) displays the following warning when a user attempts to load a potentially unsafe report:

report-designer-load-report-warning

A report is considered unsafe if it or any of its subreports contain any of the following:

Important

If you have not yet done so, be sure to review the following help topic: DevExpress Reporting - Security Considerations.

The following code prevents users from loading unsafe reports:

static class Program {
    static void Main() {
        DevExpress.XtraReports.Configuration.Settings.Default.UserDesignerOptions.ReportLoadingRestrictionLevel =
    DevExpress.XtraReports.UI.RestrictionLevel.Disable;
    }
}

The code above displays the error message when the user attempts to load a potentially unsafe report.

report-designer-load-report-disabled-warning

In a restricted environment where all reports are guaranteed to be safe, you can disable this warning and allow users to load any report by setting the UserDesignerOptions.ReportLoadingRestrictionLevel property to RestrictionLevel.Enable.

The following code lets you determine whether a report is considered unsafe, and displays detected security warnings in the Output window:

var traceSource = DevExpress.XtraPrinting.Tracer.GetSource("DXperience.Reporting", 
    System.Diagnostics.SourceLevels.Error | System.Diagnostics.SourceLevels.Warning);
var listener = new System.Diagnostics.DefaultTraceListener();
traceSource.Listeners.Add(listener);
try {
    new XtraReport1().ShowRibbonDesignerDialog();
} finally {
    traceSource.Listeners.Remove(listener);
}