private async void ExecuteAndDownload(object sender, RoutedEventArgs e) { var query = sender.As <FrameworkElement>()?.DataContext?.As <FormatedQuery>(); if (query == null) { return; } if (string.IsNullOrWhiteSpace(query.DefaultExportPath)) { MessageBox.Show("Default Export Path is Emapty. Please set a proper default path.", "Error", MessageBoxButton.OK); return; } var data = await athena.GetQueryData(query); string filePath = $"{options.DataRootPath}/{query.DefaultExportPath}.{DateTime.Now.ToString("yyyyMMdd.HHmmss")}.csv"; if (options.DataRootPath.StartsWith(".")) { filePath = AppContext.BaseDirectory + "/" + filePath; } FileInfo file = new FileInfo(filePath); var dir = file.Directory; while (dir != null) { if (!Directory.Exists(dir.FullName)) { Directory.CreateDirectory(dir.FullName); } dir = dir.Parent; } CsvFile.Dump(filePath, data.Data, data.Columns); }