// --- OPEN FILE void MsgOpenFile_Handler(GenericMessageAction <MsgOpenFile, MsgOpenFile> msg) { MsgOpenFile data = msg.Data; FileDialogResult r = DialogController.ShowOpenFileDialog(data.Multiselect); data.FileName = r.FileName; data.FileNames = r.FileNames; data.NewFile = r.CommonDialogReturn; msg.Execute(data); }
/// <summary> /// Shows a SaveFileDialog window with standard settings for this application. /// </summary> /// <returns>A structure containing information returned by a CommonDialog window.</returns> public static FileDialogResult ShowSaveFileDialog() { SaveFileDialog dlg = new SaveFileDialog(); dlg.DefaultExt = "pdf"; dlg.Title = App.Current.FindResource("loc_saveFileDialogTitle").ToString(); dlg.Filter = App.Current.FindResource("loc_saveFileDialogFilter").ToString(); dlg.AddExtension = true; DialogResult dlgresult = dlg.ShowDialog(); FileDialogResult result = new FileDialogResult(); if (dlgresult == DialogResult.OK) { result.CommonDialogReturn = true; } result.FileName = dlg.FileName; return(result); }
/// <summary> /// Shows a OpenFileDialog window with standard settings for this application. /// </summary> /// <param name="multiselect">Indicates whether OpenFileDialog should allow multiple file selection</param> /// <returns>A structure containing information returned by a CommonDialog window.</returns> public static FileDialogResult ShowOpenFileDialog(bool multiselect) { OpenFileDialog dlg = new OpenFileDialog(); dlg.DefaultExt = "pdf"; dlg.Multiselect = multiselect; dlg.Title = App.Current.FindResource("loc_openFileDialogTitle").ToString(); dlg.Filter = App.Current.FindResource("loc_openFileDialogFilter").ToString(); DialogResult dlgresult = dlg.ShowDialog(); FileDialogResult result = new FileDialogResult(); if (dlgresult == DialogResult.OK) { result.CommonDialogReturn = true; } result.FileName = dlg.FileName; ///* In multiselection, OpenFileDialog puts the last selected file at the beginning of the list (array) // * of the returned file. I avoid this with the below code. */ List <string> fileNames = new List <string>(); fileNames.AddRange(dlg.FileNames); if (fileNames.Count > 1) { fileNames.RemoveAt(0); fileNames.Add(dlg.FileNames[0]); } result.FileNames = fileNames.ToArray(); return(result); }
// --- SAVE FILE void MsgSaveFile_Handler(GenericMessageAction <MsgSaveFile, MsgOpenFile> msg) { FileDialogResult r = DialogController.ShowSaveFileDialog(); msg.Execute(new MsgOpenFile(r.FileName, r.CommonDialogReturn)); }