Skip to main content

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.v22.1.Web.dll

Declaration

public class WebDashboardExporter :
    DashboardExporterBase,
    IDisposable

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:

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:

View Example

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);
            });
        }
    });
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the WebDashboardExporter class.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also