Example T590027
Visible to All Users

BI Dashboard for MVC - How to implement server-side export

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:

Files to look at

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

MvcDashboard_ServerExport/Controllers/HomeController.cs
C#
using DevExpress.DashboardCommon; using DevExpress.DashboardWeb; using System; using System.IO; using System.Net; using System.Web.Mvc; using System.Xml; 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 serverPath = Server.MapPath(@"~/App_Data/Export"); if(!Directory.Exists(serverPath)) { Directory.CreateDirectory(serverPath); } string filePath = Path.Combine(serverPath, dashboardID); string uniqueId = "_" + dateTimeNow + ".pdf"; var exporter = new WebDashboardExporter(DashboardConfigurator.Default); exporter.ExportToPdf(dashboardID, stream, new System.Drawing.Size(1024, 768), dashboardState, pdfOptions); SaveFile(stream, filePath + uniqueId); ContentResult result = new ContentResult(); result.Content = filePath + uniqueId; return result; } } private void SaveFile(MemoryStream stream, string path) { var fileStream = System.IO.File.Create(path); stream.WriteTo(fileStream); fileStream.Close(); } } }
MvcDashboard_ServerExport/Scripts/DashboardExport.js
JavaScript
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.getDashboardState(); $.ajax({ url: 'Home/ExportDashboardToPdf', data: { DashboardID: dashboardID, DashboardState: dashboardStateJson }, type: 'POST', success: function (result) { DevExpress.ui.notify({ message: 'A dashboard was exported to ' + result, shading: true }, "success", 5000); } }); } }); }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.