private void SetDialogProperties(FileDialogNative.IFileDialog dialog) { // Description if (!string.IsNullOrEmpty(descriptionText)) { if (UseDescriptionForTitle) { dialog.SetTitle(descriptionText); } else { FileDialogNative.IFileDialogCustomize customize = (FileDialogNative.IFileDialogCustomize)dialog; customize.AddText(0, descriptionText); } } dialog.SetOptions(FileDialogNative.FOS.FOS_PICKFOLDERS | FileDialogNative.FOS.FOS_FORCEFILESYSTEM | FileDialogNative.FOS.FOS_FILEMUSTEXIST); if (!string.IsNullOrEmpty(selectedPath)) { string parent = Path.GetDirectoryName(selectedPath); if (parent == null || !Directory.Exists(parent)) { dialog.SetFileName(selectedPath); } else { string folder = Path.GetFileName(selectedPath); dialog.SetFolder(FileDialogNative.CreateItemFromParsingName(parent)); dialog.SetFileName(folder); } } }
internal virtual void OnBeforeVistaDialog(FileDialogNative.IFileDialog dialog) { dialog.SetDefaultExtension(this.DefaultExt); dialog.SetFileName(this.FileName); if (!string.IsNullOrEmpty(this.InitialDirectory)) { try { FileDialogNative.IShellItem initialDirectory = GetShellItemForPath(this.InitialDirectory); dialog.SetDefaultFolder(initialDirectory); dialog.SetFolder(initialDirectory); } catch (FileNotFoundException) { } } dialog.SetTitle(this.Title); dialog.SetOptions(GetOptions()); SetFileTypes(dialog); this._customPlaces.Apply(dialog); }
internal System.Windows.Forms.DialogResult ShowDialog(System.Windows.Forms.IWin32Window owner, FileDialogNative.IFileDialog f) { if (!string.IsNullOrEmpty(this.InitialDirectory)) { FileDialogNative.IShellItem item = null; try { SHCreateItemFromParsingName(this.InitialDirectory, IntPtr.Zero, typeof(FileDialogNative.IShellItem).GUID, out item); f.SetFolder(item); } catch (Exception e) { Util.Logging.Log(e); } if (item != null) { Marshal.ReleaseComObject(item); } } if (!string.IsNullOrEmpty(this.FileName)) { f.SetFileName(this.FileName); } if (!string.IsNullOrEmpty(this.Filter)) { var filter = this.Filter.Split('|'); var filters = new FileDialogNative.COMDLG_FILTERSPEC[filter.Length / 2]; for (var i = 0; i < filter.Length; i += 2) { filters[i / 2] = new FileDialogNative.COMDLG_FILTERSPEC() { pszName = filter[i], pszSpec = filter[i + 1], }; } f.SetFileTypes((uint)filters.Length, filters); f.SetFileTypeIndex((uint)this.FilterIndex); } if (!string.IsNullOrEmpty(this.Title)) { f.SetTitle(this.Title); } if (f.Show(owner.Handle) == 0) { FileDialogNative.IShellItem item; f.GetResult(out item); string ppszName; item.GetDisplayName(FileDialogNative.SIGDN.SIGDN_FILESYSPATH, out ppszName); Marshal.ReleaseComObject(item); this.FileName = ppszName; return(System.Windows.Forms.DialogResult.OK); } return(System.Windows.Forms.DialogResult.Cancel); }