dashboard-devexpress-dot-dashboardweb-3dc19c40.md
Implements a base functionality to perform server-side export of a dashboard/dashboard item displayed in the Web Dashboard.
Namespace : DevExpress.DashboardWeb
Assembly : DevExpress.Dashboard.v25.2.Web.dll
NuGet Package : DevExpress.Web.Dashboard.Common
public class WebDashboardExporter :
DashboardExporterBase,
IDisposable
Public Class WebDashboardExporter
Inherits DashboardExporterBase
Implements IDisposable
The WebDashboardExporter class provides a base export functionality and allows you to implement server export for the ASP.NET MVC Dashboard extension. You can specify a dashboard state and export options to be applied in the resulting document.
If you are using the DashboardConfigurator‘s API, pass its default instance to the WebDashboardExporter constructor.
using DevExpress.DashboardWeb;
//...
WebDashboardExporter exporter = new WebDashboardExporter(DashboardConfigurator.Default);
Imports DevExpress.DashboardWeb
'...
Private exporter As New WebDashboardExporter(DashboardConfigurator.Default)
Then, use the required method exposed by WebDashboardExporter to export a dashboard or dashboard item (such as WebDashboardExporter.ExportToPdf or WebDashboardExporter.ExportDashboardItemToImage).
Use the following classes to perform server-side export for other platforms:
This example demonstrates how to export a dashboard displayed using the ASP.NET MVC Dashboard extension on the server side using the WebDashboardExporter class. The following API is used to implement this capability:
using DevExpress.DashboardCommon;
using DevExpress.DashboardWeb;
using System;
using System.IO;
using System.Web.Mvc;
namespace MvcDashboard_ServerExport.Controllers {
public class HomeController : Controller {
public ActionResult Index() {
return View();
}
[HttpPost]
public ActionResult ExportDashboardToPdf(string DashboardID, string DashboardState) {
using (MemoryStream stream = new MemoryStream()) {
string dashboardID = DashboardID;
DashboardState dashboardState = new DashboardState();
dashboardState.LoadFromJson(DashboardState);
DashboardPdfExportOptions pdfOptions = new DashboardPdfExportOptions();
pdfOptions.ExportFilters = true;
pdfOptions.DashboardStatePosition = DashboardStateExportPosition.Below;
string dateTimeNow = DateTime.Now.ToString("yyyyMMddHHmmss");
string filePath = "~/App_Data/Export/" + dashboardID + "_" + dateTimeNow + ".pdf";
ASPxDashboardExporter exporter = new ASPxDashboardExporter(DashboardConfigurator.Default);
exporter.ExportToPdf(dashboardID, stream, new System.Drawing.Size(1024, 768), dashboardState, pdfOptions);
SaveFile(stream, filePath);
ContentResult result = new ContentResult();
result.Content = filePath;
return result;
}
}
private void SaveFile(MemoryStream stream, string path) {
var fileStream = System.IO.File.Create(Server.MapPath(path));
stream.WriteTo(fileStream);
fileStream.Close();
}
}
}
Imports System.IO
Imports System.Web.Mvc
Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardWeb
Namespace MvcDashboard_ServerExport.Controllers
Public Class HomeController
Inherits Controller
Public Function Index() As ActionResult
Return View()
End Function
<HttpPost> _
Public Function ExportDashboardToPdf(ByVal DashboardID As String, ByVal DashboardState As String) As ActionResult
Using stream As New MemoryStream()
Dim dashboardID_Renamed As String = DashboardID
Dim dashboardState_Renamed As New DashboardState()
dashboardState_Renamed.LoadFromJson(DashboardState)
Dim pdfOptions As New DashboardPdfExportOptions()
pdfOptions.ExportFilters = True
pdfOptions.DashboardStatePosition = DashboardStateExportPosition.Below
Dim dateTimeNow As String = Date.Now.ToString("yyyyMMddHHmmss")
Dim filePath As String = "~/App_Data/Export/" & dashboardID_Renamed & "_" & dateTimeNow & ".pdf"
Dim exporter As New ASPxDashboardExporter(DashboardConfigurator.Default)
exporter.ExportToPdf(dashboardID_Renamed, stream, New System.Drawing.Size(1024, 768), dashboardState_Renamed, pdfOptions)
SaveFile(stream, filePath)
Dim result As New ContentResult()
result.Content = filePath
Return result
End Using
End Function
Private Sub SaveFile(ByVal stream As MemoryStream, ByVal path As String)
Dim fileStream = System.IO.File.Create(Server.MapPath(path))
stream.WriteTo(fileStream)
fileStream.Close()
End Sub
End Class
End Namespace
function onBeforeRender(sender) {
var control = sender.getDashboardControl();
control.registerExtension(new DevExpress.Dashboard.DashboardPanelExtension(control));
$("#buttonContainer").dxButton({
text: "Export to PDF",
onClick: function (param) {
var dashboardID = control.dashboardContainer().id;
var dashboardStateJson = control.dashboard().state();
$.ajax({
url: 'Home/ExportDashboardToPdf',
data: {
DashboardID: dashboardID,
DashboardState: JSON.stringify(dashboardStateJson)
},
type: 'POST',
}).success(function (result) {
DevExpress.ui.notify('A dashboard was exported to ' + result, 'success', 5000);
});
}
});
}
Object DashboardExporterBase WebDashboardExporter ASPxDashboardExporter
See Also
Manage Exporting Capabilities (ASP.NET MVC)
Manage Exporting Capabilities (ASP.NET Core)