/// <remarks> /// Handles report export to .xlsx file on button click /// </remarks> /// <param name="sender"></param> /// <param name="e"></param> private void btnExport_Click(object sender, RoutedEventArgs e) { ReportService reportSrv = new ReportService(); List<ExportBO> exportReportList = new List<ExportBO>(); //converts List<BookingBO> to List <ExportBO> if (_output != null && _output.Count != 0) { foreach (BookingBO booking in _output) { ExportBO item = new ExportBO(booking); exportReportList.Add(item); } } //converts List to DataTable and adds DataTable to DataSet System.Data.DataTable dtReport = reportSrv.ToDataTable<ExportBO>(exportReportList); DataSet dsReport = new DataSet(); dsReport.Tables.Add(dtReport); //determines path for report file string reportFileName = "report.xlsx"; string currentExecutionDirPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string reportFilePath = string.Format("{0}\\{1}{2}", currentExecutionDirPath, DateTime.Now.ToString("MMMMdd_yyyy_H_mm_ss"), reportFileName); //saving report to excel reportSrv.ExportToExcel(dsReport, reportFilePath); // check if file exists and open, if exists. FileInfo fi = new FileInfo(reportFilePath); if (fi.Exists) { System.Diagnostics.Process.Start(reportFilePath); } else { //file doesn't exist } }