Skip to main content
A newer version of this page is available. .

How to: Update the Extract Data File at Runtime

  • 2 minutes to read

This example demonstrates how to update the extract data file at runtime.

how-to-update-extract-data-file-at-runtime

The application creates a copy of the dashboard, calls the DashboardExtractDataSource.UpdateExtractFile method to update the Extract data and saves the updated file with a different name because the original data file is locked. Subsequently the DashboardViewer.ReloadData() method is called. The DashboardViewer.ConfigureDataConnection event occurs before a dashboard binds to the data source, and the event handler copies the updated extract data file over the working data file.

using DevExpress.DashboardCommon;
using System.IO;
using System.Windows;

namespace UpdateExtractDataSourceExample
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : DevExpress.Xpf.Core.ThemedWindow
    {
        public MainWindow() {
            InitializeComponent();
            dashboardControl1.LoadDashboard(@"update_data_extract_dashboard.xml");
        }

        private void dashboardControl1_ConfigureDataConnection(object sender, DashboardConfigureDataConnectionEventArgs e) {
            ExtractDataSourceConnectionParameters parameters = e.ConnectionParameters as ExtractDataSourceConnectionParameters;
            if(parameters != null) {
                string current = parameters.FileName;
                string updated = parameters.FileName + "_updated";
                if(File.Exists(updated)) {
                    File.Delete(current);
                    File.Copy(updated, current);
                    File.Delete(updated);
                }
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e) {
            Dashboard dashboard = new Dashboard();
            dashboard.LoadFromXDocument(dashboardControl1.Dashboard.SaveToXDocument());
            DashboardExtractDataSource extract = dashboard.DataSources.FindFirst(d => d is DashboardExtractDataSource) as DashboardExtractDataSource;
            extract.FileName += "_updated";
            extract.UpdateExtractFile();
            dashboard.Dispose();
            dashboardControl1.ReloadData();
        }
    }
}