private bool ValidateFileSavePath(string filePath, FileDialogCreationArgs args) { if (args.PreventSaveToInstallPath && filePath.StartsWith(Platform.InstallDirectory)) { ShowMessageBox(SR.ErrorSaveFileToInstallPath, null, MessageBoxActions.Ok); return(false); } return(true); }
public static IEnumerable <string> GetFiles(FileDialogCreationArgs args) { ExtendedOpenFilesDialog xp = new ExtendedOpenFilesDialog(); IExtendedOpenFilesDialogProvider provider = xp.CreateExtension() as IExtendedOpenFilesDialogProvider; if (provider == null) { throw new NotSupportedException(); } return(provider.GetFiles(args)); }
private void PrepareFileDialog(FileDialog dialog, FileDialogCreationArgs args) { dialog.AddExtension = !string.IsNullOrEmpty(args.FileExtension); dialog.DefaultExt = args.FileExtension; dialog.FileName = args.FileName; dialog.InitialDirectory = args.Directory; dialog.RestoreDirectory = true; dialog.Title = args.Title; dialog.Filter = StringUtilities.Combine(args.Filters, "|", f => f.Description + "|" + f.Filter); }
public IEnumerable <string> GetFiles(FileDialogCreationArgs args) { var dialog = new OpenFileDialog(); PrepareFileDialog(dialog, args); dialog.CheckFileExists = true; dialog.ShowReadOnly = true; dialog.Multiselect = true; var dr = dialog.ShowDialog(); return(dr == DialogResult.OK ? dialog.FileNames : null); }
/// <summary> /// Shows a 'Open file' dialog in front of this window. /// </summary> /// <param name="args"></param> /// <returns></returns> public virtual FileDialogResult ShowOpenFileDialogBox(FileDialogCreationArgs args) { var dialog = new OpenFileDialog(); PrepareFileDialog(dialog, args); dialog.CheckFileExists = true; dialog.ShowReadOnly = false; dialog.Multiselect = args.MultiSelect; var dr = dialog.ShowDialog(_form); if (dr == DialogResult.OK) { return(new FileDialogResult(DialogBoxAction.Ok, dialog.FileNames)); } return(new FileDialogResult(DialogBoxAction.Cancel, (string)null)); }
public IEnumerable <string> GetFiles(FileDialogCreationArgs args) { OpenFileDialog dialog = new OpenFileDialog(); PrepareFileDialog(dialog, args); dialog.CheckFileExists = true; dialog.ShowReadOnly = false; dialog.Multiselect = true; DialogResult dr = dialog.ShowDialog(); if (dr == DialogResult.OK) { return(dialog.FileNames); } return(null); }
public void BrowseFiles() { try { var args = new FileDialogCreationArgs(); args.Filters.Add(new FileExtensionFilter("*.pdf", "PDF files (*.pdf)")); var result = this.Host.DesktopWindow.ShowOpenFileDialogBox(args); if (result.Action == DialogBoxAction.Ok) { this.FilePath = result.FileName; NotifyPropertyChanged("FilePath"); } } catch (Exception e) { ExceptionHandler.Report(e, this.Host.DesktopWindow); } }
public void Open() { FileDialogCreationArgs args = new FileDialogCreationArgs(string.Empty) { Title = @"Open File Set", FileExtension = string.Empty }; args.Filters.Add(new FileExtensionFilter("DICOMDIR; *.dcm", @"All Support File")); args.Filters.Add(new FileExtensionFilter("*.*", @"All Files")); FileDialogResult result = base.Context.DesktopWindow.ShowOpenFileDialogBox(args); if (result.Action == DialogBoxAction.Ok) { FileName = result.FileName; } base.Context.Component.Load(FileName); }
public void AddItems() { FileDialogCreationArgs args = new FileDialogCreationArgs(string.Empty); args.Filters.Add(new FileExtensionFilter("*.*", SR.LabelAllFiles)); args.Directory = _lastFolder; IEnumerable <string> paths = ExtendedOpenFilesDialog.GetFiles(args); if (paths != null) { foreach (string s in paths) { _lastFolder = Path.GetDirectoryName(s); break; } base.Load(false, paths); } }
public void ImportAimXml() { // 1. Pick AIM XML documents to import FileDialogCreationArgs fileDialogCreationArgs = new FileDialogCreationArgs(string.Empty, _lastFolder, null, new List <FileExtensionFilter> { new FileExtensionFilter("*.xml", "XML Files (*.xml)"), new FileExtensionFilter("*.*", "All Files (*.*)") }); fileDialogCreationArgs.Title = "Select AIM XML documents"; IEnumerable <string> aimFiles = Utilities.ExtendedOpenFilesDialog.GetFiles(fileDialogCreationArgs); // 2. Import selection if (aimFiles != null) { DoImportAimXml(new List <string>(aimFiles)); } }
/// <summary> /// Shows a 'Save file' dialog in front of this window. /// </summary> /// <param name="args"></param> /// <returns></returns> public virtual FileDialogResult ShowSaveFileDialogBox(FileDialogCreationArgs args) { var dialog = new SaveFileDialog(); PrepareFileDialog(dialog, args); dialog.OverwritePrompt = true; dialog.FileOk += (sender, e) => { if (!ValidateFileSavePath(dialog.FileName, args)) { e.Cancel = true; } }; var dr = dialog.ShowDialog(_form); if (dr == DialogResult.OK) { return(new FileDialogResult(DialogBoxAction.Ok, dialog.FileName)); } return(new FileDialogResult(DialogBoxAction.Cancel, (string)null)); }
public string SaveXmlAs(Uri uri) { string defaultFilename = GetDefaultFilename(uri); FileDialogCreationArgs fileDialogCreationArgs = new FileDialogCreationArgs( defaultFilename, DefaultPath, ".xml", new List <FileExtensionFilter>() { new FileExtensionFilter("*.xml", "XML Files"), new FileExtensionFilter("*.*", "All Files") }); FileDialogResult result = Host.DesktopWindow.ShowSaveFileDialogBox(fileDialogCreationArgs); string filename = result.FileName; // Write the xml file if it doesn't exist or is Ok to overwite if (result.Action == DialogBoxAction.Ok) { _webClient.DownloadFileAsync(uri, filename); } _savedFilename = filename; return(filename); }
/// <summary> /// Shows a 'Open file' dialog in front of this window. /// </summary> /// <param name="args"></param> /// <returns></returns> public virtual FileDialogResult ShowOpenFileDialogBox(FileDialogCreationArgs args) { throw new NotSupportedException(); }
private bool ValidateFileSavePath(string filePath, FileDialogCreationArgs args) { if (args.PreventSaveToInstallPath && filePath.StartsWith(Platform.InstallDirectory)) { ShowMessageBox(SR.ErrorSaveFileToInstallPath, null, MessageBoxActions.Ok); return false; } return true; }
/// <summary> /// Shows a 'Save file' dialog in front of this window. /// </summary> /// <param name="args"></param> /// <returns></returns> public virtual FileDialogResult ShowSaveFileDialogBox(FileDialogCreationArgs args) { var dialog = new SaveFileDialog(); PrepareFileDialog(dialog, args); dialog.OverwritePrompt = true; dialog.FileOk += (sender, e) => { if(!ValidateFileSavePath(dialog.FileName, args)) { e.Cancel = true; } }; var dr = dialog.ShowDialog(_form); if(dr == DialogResult.OK) { return new FileDialogResult(DialogBoxAction.Ok, dialog.FileName); } return new FileDialogResult(DialogBoxAction.Cancel, (string)null); }
/// <summary> /// Shows a 'Open file' dialog in front of this window. /// </summary> /// <param name="args"></param> /// <returns></returns> public virtual FileDialogResult ShowOpenFileDialogBox(FileDialogCreationArgs args) { var dialog = new OpenFileDialog(); PrepareFileDialog(dialog, args); dialog.CheckFileExists = true; dialog.ShowReadOnly = false; dialog.Multiselect = args.MultiSelect; var dr = dialog.ShowDialog(_form); if (dr == DialogResult.OK) { return new FileDialogResult(DialogBoxAction.Ok, dialog.FileNames); } return new FileDialogResult(DialogBoxAction.Cancel, (string)null); }
private bool PromptSaveDestination(out Dictionary <string, string> filenames) { var storeLocation = GetCanonicalPath(StudyStore.FileStoreDirectory) + Path.DirectorySeparatorChar; filenames = null; if (_loadedFiles.Count > 1) { string selectedPath; var args = new SelectFolderDialogCreationArgs { AllowCreateNewFolder = true, Prompt = SR.MessageSelectDestinationFolder }; do { // show select folder dialog var result = Host.DesktopWindow.ShowSelectFolderDialogBox(args); if (result.Action != DialogBoxAction.Ok || string.IsNullOrWhiteSpace(result.FileName)) { return(false); } args.Path = selectedPath = result.FileName; if ((GetCanonicalPath(selectedPath) + Path.DirectorySeparatorChar).StartsWith(storeLocation)) { // if selected path is under the filestore location, make user choose another one var message = SR.MessageFileStoreNotValidSaveLocation; Host.DesktopWindow.ShowMessageBox(message, MessageBoxActions.Ok); selectedPath = string.Empty; } else if (Directory.Exists(selectedPath) && Directory.EnumerateFiles(selectedPath).Any()) { // if selected path contains files, confirm that operation will overwrite files, or let user choose another one var message = SR.MessageOutputFolderNotEmptyConfirmOverwriteFiles; if (Host.DesktopWindow.ShowMessageBox(message, MessageBoxActions.YesNo) != DialogBoxAction.Yes) { selectedPath = string.Empty; } } } while (string.IsNullOrWhiteSpace(selectedPath)); // create the file map using new filenames in the selected path var n = 0; filenames = _loadedFiles.ToDictionary(f => f.Filename, f => Path.Combine(selectedPath, string.Format("{0:D8}.dcm", ++n))); return(true); } else { string targetFilename; var originalFilename = _loadedFiles[0].Filename; var args = new FileDialogCreationArgs(originalFilename) { PreventSaveToInstallPath = true, Title = SR.TitleSaveAs }; args.Filters.Add(new FileExtensionFilter("*.*", SR.LabelAllFiles)); do { // show save file dialog var result = Host.DesktopWindow.ShowSaveFileDialogBox(args); if (result.Action != DialogBoxAction.Ok || string.IsNullOrWhiteSpace(result.FileName)) { return(false); } targetFilename = result.FileName; if (GetCanonicalPath(targetFilename).StartsWith(storeLocation)) { // if destination file is in filestore, make user choose another one var message = SR.MessageFileStoreNotValidSaveLocation; Host.DesktopWindow.ShowMessageBox(message, MessageBoxActions.Ok); targetFilename = string.Empty; } // save dialog handles prompting if destination file already exists } while (string.IsNullOrWhiteSpace(targetFilename)); // create file map with the one single entry filenames = new Dictionary <string, string> { { originalFilename, targetFilename } }; return(true); } }