private async void OnExport() { var specialities = await _repo.GetSpecialtiesWithFacultyAsync(); var exportType = ExportType.All.FirstOrDefault(et => et.Id == SelectedExportTypeId); Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.FileName = "Specialities"; dlg.DefaultExt = exportType.DefaultExt; dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); dlg.Filter = exportType.Name + "|" + exportType.DefaultExt; // Show save file dialog box bool?result = dlg.ShowDialog(); // Process save file dialog box results if (!result.HasValue || result == false) { return; } string filename = dlg.FileName; switch (SelectedExportTypeId) { case ExportType.txtId: ExportToTxtFile(filename, specialities); break; case ExportType.csvId: ExportToCsvFile(filename, specialities); break; } }