dashboard-devexpress-dot-dashboardcommon-27d25d0e.md
Allows you to implement server export of a dashboard or dashboard items for all platforms.
Namespace : DevExpress.DashboardCommon
Assembly : DevExpress.Dashboard.v25.2.Core.dll
NuGet Package : DevExpress.Dashboard.Core
public class DashboardExporter :
DashboardExporterBase
Public Class DashboardExporter
Inherits DashboardExporterBase
The non-visual DashboardExporter component allows you to export the DevExpress BI Dashboard as a PDF, XLS, XLSX, and image (PNG, JPEG, SVG, GIF) without referencing dashboard UI controls ( DashboardDesigner, DashboardViewer, ASPxDashboard, and so on) or DashboardConfigurator.
To integrate the DashboardExporter into a service, register the DevExpress NuGet feed as a package source and install the DevExpress.Dashboard.Core package.
Then, create a DashboardExporter instance and use its events to configure a dashboard and the dashboard’s data sources. Call exporter’s methods to export a dashboard or dashboard item (such as DashboardExporter.ExportToPdf or DashboardExporter.ExportDashboardItemToImage).
You can also specify a dashboard state and export options to be applied in the resulting document. For this, pass a DashboardState object and the specified export options (such as DashboardPdfExportOptions or DashboardExcelExportOptions) as parameters to the ExportTo... methods.
The following code example exports a dashboard in PDF format in a console application:
View Example: BI Dashboard - Non-Visual Export Component
The DashboardExporter.ExportToPdf method exports a dashboard in a Pdf file. The following events is used to detect and display possible errors:
using System;
using System.IO;
using DevExpress.DashboardCommon;
namespace DashboardExporterApp {
class Program {
static void Main(string[] args) {
if(args.Length < 1 || !Directory.Exists(args[0])) {
Console.WriteLine("Path to the dashboard and output folders are required");
return;
}
string[] dashboards = Directory.GetFiles(args[0], "*.xml");
string outputFolder = args[1];
DashboardExporter exporter = new DashboardExporter();
exporter.ConnectionError += Exporter_ConnectionError;
exporter.DataLoadingError += Exporter_DataLoadingError;
exporter.DashboardItemDataLoadingError += Exporter_DashboardItemDataLoadingError;
foreach(string dashboard in dashboards) {
string outputFile = Path.Combine(outputFolder,
$"{Path.GetFileNameWithoutExtension(dashboard)}.pdf");
using FileStream stream = new FileStream(outputFile, FileMode.OpenOrCreate);
try {
exporter.ExportToPdf(dashboard, stream);
}
catch(Exception e) {
Console.WriteLine($"Unable to export {dashboard}.");
Console.WriteLine(e.Message);
continue;
}
}
Console.WriteLine("Done!");
}
static void Exporter_ConnectionError(object sender,
DashboardExporterConnectionErrorEventArgs e) {
Console.WriteLine(
$"The following error occurs in {e.DataSourceName}: {e.Exception.Message}");
}
static void Exporter_DataLoadingError(object sender,
DataLoadingErrorEventArgs e) {
foreach(DataLoadingError error in e.Errors)
Console.WriteLine(
$"The following error occurs in {error.DataSourceName}: {error.Error}");
}
static void Exporter_DashboardItemDataLoadingError(object sender,
DashboardItemDataLoadingErrorEventArgs e) {
foreach(DashboardItemDataLoadingError error in e.Errors)
Console.WriteLine(
$"The following error occurs in {error.DashboardItemName}: {error.Error}");
}
}
}
Imports System
Imports System.IO
Imports DevExpress.DashboardCommon
Namespace DashboardExporterApp
Friend Class Program
Shared Sub Main(ByVal args() As String)
If args.Length < 1 OrElse Not Directory.Exists(args(0)) Then
Console.WriteLine("Path to the dashboard and output folders are required")
Return
End If
Dim dashboards() As String = Directory.GetFiles(args(0), "*.xml")
Dim outputFolder As String = args(1)
Dim exporter As New DevExpress.DashboardCommon.DashboardExporter()
AddHandler exporter.ConnectionError, AddressOf Exporter_ConnectionError
AddHandler exporter.DataLoadingError, AddressOf Exporter_DataLoadingError
AddHandler exporter.DashboardItemDataLoadingError, AddressOf Exporter_DashboardItemDataLoadingError
For Each dashboard As String In dashboards
Dim outputFile As String = Path.Combine(outputFolder, $"{Path.GetFileNameWithoutExtension(dashboard)}.pdf")
Using stream = New FileStream(outputFile, FileMode.OpenOrCreate)
Try
exporter.ExportToPdf(dashboard, stream)
Catch e As Exception
Console.WriteLine($"Unable to export {dashboard}.")
Console.WriteLine(e.Message)
Continue For
End Try
End Using
Next dashboard
Console.WriteLine("Done!")
End Sub
Private Shared Sub Exporter_ConnectionError(ByVal sender As Object, ByVal e As DashboardExporterConnectionErrorEventArgs)
Console.WriteLine($"The following error occurs in {e.DataSourceName}: {e.Exception.Message}")
End Sub
Private Shared Sub Exporter_DataLoadingError(ByVal sender As Object, ByVal e As DataLoadingErrorEventArgs)
For Each [error] As DataLoadingError In e.Errors
Console.WriteLine($"The following error occurs in {[error].DataSourceName}: {[error].Error}")
Next [error]
End Sub
Private Shared Sub Exporter_DashboardItemDataLoadingError(ByVal sender As Object, ByVal e As DashboardItemDataLoadingErrorEventArgs)
For Each [error] As DashboardItemDataLoadingError In e.Errors
Console.WriteLine($"The following error occurs in {[error].DashboardItemName}: {[error].Error}")
Next [error]
End Sub
End Class
End Namespace
This example uses the DashboardExporter component in a console application to export a dashboard with a custom Funnel item.
View Example: BI Dashboard - Non-Visual Custom Export
This example sends a dashboard as an email with the MailKit email client library.
View Example: BI Dashboard - How to Use MailKit to Send a Dashboard as a Document in PDF
The following example uses the DashboardExporter component in a console application to email a dashboard that displays different data depending on the addressee. The MailKit email client library is used in this example.
Object DashboardExporterBase DashboardExporter
See Also