public void ExportToCSV(List<Object> listContact) { var exportList = ObjConvertToContactDB(listContact); if (exportList.Count() == 0) { MessageBox.Show(CMLibrary.Properties.Resources.choose_contact_to_export); return; } string fileName = "contacts_" + (DateTime.Now.ToString("MM-dd-yyyy hhmmss")) + ".csv"; saveFileDialog.FileName = fileName; if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string path = ""; try { path = saveFileDialog.FileName; if (path.Length >= 200) { MessageBox.Show(CMLibrary.Properties.Resources.invalid_file_name_path, CMLibrary.Properties.Resources.Destination_path_to_long, MessageBoxButton.OK); return; //saveFileDialog.FileName = fileName; //this.ExportToCSV(); } } catch (System.IO.PathTooLongException) { MessageBox.Show(CMLibrary.Properties.Resources.invalid_file_name_path, CMLibrary.Properties.Resources.Destination_path_to_long, MessageBoxButton.OK); return; //saveFileDialog.FileName = fileName; //this.ExportToCSV(); } FileImExportController fileImEx = new FileImExportController(); int res = fileImEx.ExportToCSVFile(exportList, path); if (res > 0) { MessageBox.Show(CMLibrary.Properties.Resources.export_success); } else { MessageBox.Show(CMLibrary.Properties.Resources.export_error); } } }
private void ExportToCSV() { List<ContactDB> exportList = GetCheckedContactList(); if (exportList.Count() == 0) { MessageBox.Show(CMLibrary.Properties.Resources.choose_contact_to_export); return; } string fileName = "contacts_" + (DateTime.Now.ToString("MM-dd-yyyy hhmmss")); saveFileDialog.FileName = fileName; if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string path = saveFileDialog.FileName; FileImExportController fileImEx = new FileImExportController(); int res = fileImEx.ExportToCSVFile(exportList, path); if (res > 0) { MessageBox.Show(CMLibrary.Properties.Resources.export_success); } else { MessageBox.Show(CMLibrary.Properties.Resources.export_error); } } }
private async void ExportToCSV() { List<ContactDB> exportList = GetCheckedContactList(); if (exportList.Count() == 0) { MessageDialog dialog = new MessageDialog("Please choose contact(s) to export."); await dialog.ShowAsync(); return; } string fileName = "contacts_" + (DateTime.Now.ToString("MM-dd-yyyy hhmmss")); FileSavePicker savePicker = new FileSavePicker(); savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; savePicker.FileTypeChoices.Add("CSV file(.csv)|*.csv", new List<string>() { ".csv" }); savePicker.SuggestedFileName = fileName; StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { FileImExportController fileImEx = new FileImExportController(); int res = await fileImEx.ExportToCSVFile(exportList, file); if (res == 1) { MessageDialog dialog = new MessageDialog("Export successfully."); await dialog.ShowAsync(); } else { MessageDialog dialog = new MessageDialog("Export not successfully"); await dialog.ShowAsync(); } } }
public async void ExportToCSV(List<ContactD> exportList) { try { if (exportList.Count() == 0) { var msg = UC_AddressBook.ResourcesStringLoader.GetString("choose_contact_to_export"); Modals.UIConfirmPopup.ShowAsyncInfoPopup(msg); return; } string fileName = "contacts_" + (DateTime.Now.ToString("MM-dd-yyyy hhmmss")); FileSavePicker savePicker = new FileSavePicker(); savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; savePicker.FileTypeChoices.Add("CSV file(.csv)|*.csv", new List<string>() { ".csv" }); savePicker.SuggestedFileName = fileName; StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { FileImExportController fileImEx = new FileImExportController(); int res = await fileImEx.ExportToCSVFile(exportList, file); if (res == 1) { string msg = UC_AddressBook.ResourcesStringLoader.GetString("DIALOG-Message-export_success"); Modals.UIConfirmPopup.ShowAsyncInfoPopup(msg); } else { string msg = UC_AddressBook.ResourcesStringLoader.GetString("DIALOG-Message-ExportError"); Modals.UIConfirmPopup.ShowAsyncInfoPopup(msg); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); string msg = UC_AddressBook.ResourcesStringLoader.GetString("DIALOG-Message-ExportError"); Modals.UIConfirmPopup.ShowAsyncInfoPopup(msg); } }