internal static string GetFilePathFromShellItem(FileDialogNative.IShellItem item) { string filename; item.GetDisplayName(FileDialogNative.SIGDN.SIGDN_DESKTOPABSOLUTEPARSING, out filename); return(filename); }
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 void Apply(FileDialogNative.IFileDialog dialog) { //Walk backwards for (int i = this.Items.Count - 1; i >= 0; --i) { FileDialogCustomPlace customPlace = this.Items[i]; // Fix for Dev10 bug 536188: we need permission to check whether the specified path exists FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.PathDiscovery, customPlace.Path); permission.Demand(); try { FileDialogNative.IShellItem shellItem = customPlace.GetNativePath(); if (null != shellItem) { dialog.AddPlace(shellItem, 0); } } catch (FileNotFoundException) { } //Silently absorb FileNotFound exceptions (these could be caused by a path that disappeared after the place was added to the dialog). } }
internal static string GetFilePathFromShellItem(FileDialogNative.IShellItem item) { string str; item.GetDisplayName((FileDialogNative.SIGDN)(-2147319808), out str); return(str); }
internal static FileDialogNative.IShellItem GetShellItemForPath(string path) { FileDialogNative.IShellItem ppsi = null; IntPtr zero = IntPtr.Zero; uint rgflnOut = 0; if ((0 > System.Windows.Forms.UnsafeNativeMethods.Shell32.SHILCreateFromPath(path, out zero, ref rgflnOut)) || (0 > System.Windows.Forms.UnsafeNativeMethods.Shell32.SHCreateShellItem(IntPtr.Zero, IntPtr.Zero, zero, out ppsi))) { throw new FileNotFoundException(); } return(ppsi); }
internal static FileDialogNative.IShellItem GetShellItemForPath(string path) { FileDialogNative.IShellItem ret = null; IntPtr pidl = IntPtr.Zero; uint zero = 0; if (0 <= UnsafeNativeMethods.Shell32.SHILCreateFromPath(path, out pidl, ref zero)) { if (0 <= UnsafeNativeMethods.Shell32.SHCreateShellItem( IntPtr.Zero, //No parent specified IntPtr.Zero, pidl, out ret)) { return(ret); } } throw new System.IO.FileNotFoundException(); }
internal void Apply(FileDialogNative.IFileDialog dialog) { for (int i = base.Items.Count - 1; i >= 0; i--) { FileDialogCustomPlace place = base.Items[i]; new FileIOPermission(FileIOPermissionAccess.PathDiscovery, place.Path).Demand(); try { FileDialogNative.IShellItem nativePath = place.GetNativePath(); if (nativePath != null) { dialog.AddPlace(nativePath, 0); } } catch (FileNotFoundException) { } } }
internal void Apply(FileDialogNative.IFileDialog dialog) { //Walk backwards for (int i = this.Items.Count - 1; i >= 0; --i) { FileDialogCustomPlace customPlace = this.Items[i]; try { FileDialogNative.IShellItem shellItem = customPlace.GetNativePath(); if (null != shellItem) { dialog.AddPlace(shellItem, 0); } } catch (FileNotFoundException) { } //Silently absorb FileNotFound exceptions (these could be caused by a path that disappeared after the place was added to the dialog). } }
public void OnOverwrite(FileDialogNative.IFileDialog pfd, FileDialogNative.IShellItem psi, out FileDialogNative.FDE_OVERWRITE_RESPONSE pResponse) { pResponse = FileDialogNative.FDE_OVERWRITE_RESPONSE.FDEOR_DEFAULT; }
public void OnShareViolation(FileDialogNative.IFileDialog pfd, FileDialogNative.IShellItem psi, out FileDialogNative.FDE_SHAREVIOLATION_RESPONSE pResponse) { pResponse = FileDialogNative.FDE_SHAREVIOLATION_RESPONSE.FDESVR_DEFAULT; }
public int OnFolderChanging(FileDialogNative.IFileDialog pfd, FileDialogNative.IShellItem psiFolder) { return(NativeMethods.S_OK); }
public static extern int SHCreateShellItem(IntPtr pidlParent, IntPtr psfParent, IntPtr pidl, out FileDialogNative.IShellItem ppsi);
public int OnFolderChanging(FileDialogNative.IFileDialog pfd, FileDialogNative.IShellItem psiFolder) { return(0); }
internal static extern void SHCreateItemFromParsingName( [In][MarshalAs(UnmanagedType.LPWStr)] string pszPath, [In] IntPtr pbc, [In][MarshalAs(UnmanagedType.LPStruct)] Guid riid, [Out][MarshalAs(UnmanagedType.Interface, IidParameterIndex = 2)] out FileDialogNative.IShellItem ppv);
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); }