private bool RunDialog(IntPtr owner) { IFileDialog dialog = null; try { dialog = new NativeFileOpenDialog(); SetDialogProperties(dialog); int result = dialog.Show(owner); if (result < 0) { if ((uint)result == (uint)HRESULT.ERROR_CANCELLED) { return(false); } else { throw System.Runtime.InteropServices.Marshal.GetExceptionForHR(result); } } GetResult(dialog); return(true); } finally { if (dialog != null) { System.Runtime.InteropServices.Marshal.FinalReleaseComObject(dialog); } } }
public static string Show(IWin32Window parent) { IFileDialog dialog = null; try { dialog = new NativeFileOpenDialog(); dialog.SetOptions(FOS.FOS_PICKFOLDERS); if (dialog.Show(parent != null ? parent.Handle : IntPtr.Zero) == 0) { string result = string.Empty; IShellItem item; dialog.GetResult(out item); return(GetFilePathFromShellItem(item)); } else { return(null); } } finally { if (dialog != null) { Marshal.FinalReleaseComObject(dialog); } } }
private void GetNativeDialogResult(NativeFileOpenDialog nativeFileOpenDialog) { IShellItem item; nativeFileOpenDialog.GetResult(out item); item.GetDisplayName(CommonDialogNativeMethods.SIGDN.SIGDN_FILESYSPATH, out m_FolderPath); }
private void SetNativeDialogProperties(NativeFileOpenDialog nativeFileOpenDialog) { //Set Title if (!string.IsNullOrEmpty(m_Title)) { nativeFileOpenDialog.SetTitle(m_Title); } //Set Folder if (!string.IsNullOrEmpty(m_FolderPath)) { if (System.IO.Directory.Exists(m_FolderPath)) { nativeFileOpenDialog.SetFolder(CreateShellItemFromParsingName(m_FolderPath)); } else { string parent = System.IO.Path.GetDirectoryName(m_FolderPath); if (parent != null && System.IO.Directory.Exists(parent)) { string folder = System.IO.Path.GetFileName(m_FolderPath); nativeFileOpenDialog.SetFolder(CreateShellItemFromParsingName(parent)); nativeFileOpenDialog.SetFileName(folder); } } } //Apply option bitflags nativeFileOpenDialog.SetOptions(GetNativeDialogFlags()); }
private CommonDialogResult RunVistaNativeDialog(IntPtr hwndOwner) { var nativeFileOpenDialog = new NativeFileOpenDialog(); SetNativeDialogProperties(nativeFileOpenDialog); try { int hresult = nativeFileOpenDialog.Show(hwndOwner); //Create return information. if (hresult < 0) { if ((uint)hresult == (uint)HRESULT.E_ERROR_CANCELLED) { return(CommonDialogResult.Cancel); } throw Marshal.GetExceptionForHR(hresult); } GetNativeDialogResult(nativeFileOpenDialog); return(CommonDialogResult.OK); } finally { if (nativeFileOpenDialog != null) { Marshal.FinalReleaseComObject(nativeFileOpenDialog); } } }
internal override void InitializeNativeFileDialog() { if (openDialogCoClass == null) { openDialogCoClass = new NativeFileOpenDialog(); } }
public DialogResult ShowDialog() { NativeFileOpenDialog dialog = null; try { // If the caller did not specify a starting path, or set it to null, // it is not healthy as it causes SHCreateItemFromParsingName to // throw E_INVALIDARG (0x80070057). Setting it to an empty string. // if (SelectedPath == null) { SelectedPath = string.Empty; } dialog = new NativeFileOpenDialog(); dialog.SetTitle(Title); object shellItem; // IShellItem GUID Guid guid = new Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE"); int hresult = SHCreateItemFromParsingName(SelectedPath, IntPtr.Zero, ref guid, out shellItem); if ((uint)hresult != (uint)HRESULT.S_OK) { throw Marshal.GetExceptionForHR(hresult); } dialog.SetFolder((IShellItem)shellItem); dialog.SetOptions(FOS.FOS_PICKFOLDERS | FOS.FOS_FORCEFILESYSTEM | FOS.FOS_FILEMUSTEXIST); IntPtr hWnd = new WindowInteropHelper(Owner).Handle; hresult = dialog.Show(hWnd); if (hresult < 0) { if ((uint)hresult == (uint)HRESULT.E_CANCELLED) { return(DialogResult.Cancel); } throw Marshal.GetExceptionForHR(hresult); } string path; IShellItem item; dialog.GetResult(out item); item.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out path); SelectedPath = path; return(DialogResult.OK); } finally { if (dialog != null) { Marshal.FinalReleaseComObject(dialog); } } }
public DynamoOpenFileDialog(DynamoViewModel model) { this.model = model; _dialog = new NativeFileOpenDialog(); IFileDialogCustomize customize = (IFileDialogCustomize) _dialog; customize.AddCheckButton(RunManualCheckboxId, Dynamo.Wpf.Properties.Resources.FileDialogManualMode, model.PreferenceSettings.OpenFileInManualExecutionMode); }
public DynamoOpenFileDialog(DynamoViewModel model) { this.model = model; _dialog = new NativeFileOpenDialog(); IFileDialogCustomize customize = (IFileDialogCustomize)_dialog; customize.AddCheckButton(RunManualCheckboxId, Dynamo.Wpf.Properties.Resources.FileDialogManualMode, model.PreferenceSettings.OpenFileInManualExecutionMode); }
private static String[] ShowDialog(IntPtr parentWindowHandle, String title, String initialDirectory, String defaultFileName, IReadOnlyCollection <Filter> filters, Int32 selectedFilterZeroBasedIndex, FileOpenOptions flags) { NativeFileOpenDialog nfod = new NativeFileOpenDialog(); try { return(ShowDialogInner(nfod, parentWindowHandle, title, initialDirectory, defaultFileName, filters, selectedFilterZeroBasedIndex, flags)); } finally { Marshal.ReleaseComObject(nfod); } }
/// <summary>Shows the folder browser dialog. Returns null if the dialog cancelled. Otherwise returns the selected path.</summary> public static String ShowDialog(IntPtr parentHWnd, String title, String initialDirectory) { NativeFileOpenDialog nfod = new NativeFileOpenDialog(); try { return(ShowDialogInner(nfod, parentHWnd, title, initialDirectory)); } finally { Marshal.ReleaseComObject(nfod); } }
private static IReadOnlyList <String> ShowDialog(IntPtr parentHWnd, String title, String initialDirectory, String defaultFileName, IReadOnlyCollection <Filter> filters, Int32?selectedFilterZeroBasedIndex, FileOpenOptions flags) #endif { NativeFileOpenDialog nfod = new NativeFileOpenDialog(); try { return(ShowDialogInner(nfod, parentHWnd, title, initialDirectory, defaultFileName, filters, selectedFilterZeroBasedIndex: selectedFilterZeroBasedIndex ?? (-1), flags)); } finally { _ = Marshal.ReleaseComObject(nfod); } }
/// <summary> /// Specifies a common dialog box. /// </summary> /// <param name="hwndOwner">A value that represents the window handle of the owner window for the common dialog box.</param> /// <returns>true if the file could be opened; otherwise, false.</returns> protected override bool RunDialog(IntPtr hwndOwner) { if (_downlevelDialog != null) { return (_downlevelDialog.ShowDialog(hwndOwner == IntPtr.Zero ? null : new WindowHandleWrapper(hwndOwner)) == DialogResult.OK); } IFileDialog dialog = null; try { dialog = new NativeFileOpenDialog(); SetDialogProperties(dialog); int result = dialog.Show(hwndOwner); if (result < 0) { if ((uint)result == NativeMethods.ERROR_CANCELLED) { return(false); } else { throw Marshal.GetExceptionForHR(result); } } GetResult(dialog); return(true); } finally { if (dialog != null) { Marshal.FinalReleaseComObject(dialog); } } }
private bool RunDialog(IntPtr owner) { IFileDialog dialog = null; try { dialog = new NativeFileOpenDialog(); SetDialogProperties(dialog); int result = dialog.Show(owner); if (result < 0) { if ((uint) result == (uint) HRESULT.ERROR_CANCELLED) return false; else throw Marshal.GetExceptionForHR(result); } GetResult(dialog); return true; } finally { if (dialog != null) Marshal.FinalReleaseComObject(dialog); } }
public static string Show(IWin32Window parent) { IFileDialog dialog = null; try { dialog = new NativeFileOpenDialog(); dialog.SetOptions(FOS.FOS_PICKFOLDERS); if(dialog.Show(parent != null ? parent.Handle : IntPtr.Zero) == 0) { string result = string.Empty; IShellItem item; dialog.GetResult(out item); return GetFilePathFromShellItem(item); } else { return null; } } finally { if(dialog != null) { Marshal.FinalReleaseComObject(dialog); } } }
public DialogHolder() { State = NativeDialogShowState.PreShow; Dialog = new NativeFileOpenDialog(); State = NativeDialogShowState.Showing; }
public DialogResult ShowDialog() { NativeFileOpenDialog dialog = null; try { // If the caller did not specify a starting path, or set it to null, // it is not healthy as it causes SHCreateItemFromParsingName to // throw E_INVALIDARG (0x80070057). Setting it to an empty string. // if (SelectedPath == null) SelectedPath = string.Empty; dialog = new NativeFileOpenDialog(); dialog.SetTitle(Title); object shellItem; // IShellItem GUID Guid guid = new Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE"); int hresult = SHCreateItemFromParsingName(SelectedPath, IntPtr.Zero, ref guid, out shellItem); if ((uint)hresult != (uint)HRESULT.S_OK) throw Marshal.GetExceptionForHR(hresult); dialog.SetFolder((IShellItem)shellItem); dialog.SetOptions(FOS.FOS_PICKFOLDERS | FOS.FOS_FORCEFILESYSTEM | FOS.FOS_FILEMUSTEXIST); IntPtr hWnd = new WindowInteropHelper(Owner).Handle; hresult = dialog.Show(hWnd); if (hresult < 0) { if ((uint)hresult == (uint)HRESULT.E_CANCELLED) return DialogResult.Cancel; throw Marshal.GetExceptionForHR(hresult); } string path; IShellItem item; dialog.GetResult(out item); item.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out path); SelectedPath = path; return DialogResult.OK; } finally { if (dialog != null) Marshal.FinalReleaseComObject(dialog); } }
internal void InitializeNativeFileDialog() { openDialogCoClass = new NativeFileOpenDialog(); }
/// <summary> /// Specifies a common dialog box. /// </summary> /// <param name="hwndOwner">A value that represents the window handle of the owner window for the common dialog box.</param> /// <returns>true if the file could be opened; otherwise, false.</returns> protected override bool RunDialog(IntPtr hwndOwner) { if( _downlevelDialog != null ) return _downlevelDialog.ShowDialog(hwndOwner == IntPtr.Zero ? null : new WindowHandleWrapper(hwndOwner)) == DialogResult.OK; IFileDialog dialog = null; try { dialog = new NativeFileOpenDialog(); SetDialogProperties(dialog); int result = dialog.Show(hwndOwner); if( result < 0 ) { if( (uint)result == NativeMethods.ERROR_CANCELLED ) return false; else throw System.Runtime.InteropServices.Marshal.GetExceptionForHR(result); } GetResult(dialog); return true; } finally { if( dialog != null ) System.Runtime.InteropServices.Marshal.FinalReleaseComObject(dialog); } }