WebDashboardExporter Class
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.v24.2.Web.dll
Declaration
Remarks
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);
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:
- ASP.NET Web Forms: ASPxDashboardExporter
- ASP.NET Core: AspNetCoreDashboardExporter
Example
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:
- The ASPxClientDashboard.BeforeRender event is handled to obtain the client-side DashboardControl using the ASPxClientDashboard.GetDashboardControl method.
- The AJAX request is used to send the dashboard identifier and state to the server side. On the server side, these values are received as action method parameters and passed to the WebDashboardExporter.ExportToPdf method.
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();
}
}
}
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);
});
}
});
}