/// <summary> /// Enables a handler to provide status and error information for all operations. /// </summary> /// <param name="pfops">An <see cref="IFileOperationProgressSink"/> object to be used for progress status and error notifications.</param> /// <returns>A returned token that uniquely identifies this connection. The calling application uses this token later to delete the connection by passing it to <see cref="Unadvise"/>.</returns> /// <remarks>Several individual methods have the ability to declare their own progress sinks, which are redundant to the one set here. They are used when you only want to be given progress and error information for a specific operation.</remarks> /// <exception cref="ArgumentNullException">Exception thrown when a parameter is null.</exception> /// <exception cref="ObjectDisposedException">Exception thrown when this object is disposed.</exception> /// <exception cref="Win32Exception">Exception thrown when this method fails because of an error in the Win32 COM API implementation.</exception> public uint Advise(FileOperationProgressSink pfops) { if (pfops == null) { throw new ArgumentNullException(nameof(pfops)); } if (disposed) { throw new ObjectDisposedException(nameof(FileOperation)); } HResult hr = fileOperation.Advise(pfops.FileOperationProgressSinkInternal, out uint pdwCookie); if (CoreErrorHelper.Succeeded(hr)) { cookies.Add(pdwCookie); return(pdwCookie); } else { Marshal.ThrowExceptionForHR((int)hr); } return(0); }
private void BeginList() { // Get list of removed items from native code object removedItems; uint maxSlotsInList = 10; // default // Native call to start adding items to the taskbar destination list HResult hr = customDestinationList.BeginList( out maxSlotsInList, ref TaskbarNativeMethods.TaskbarGuids.IObjectArray, out removedItems); if (!CoreErrorHelper.Succeeded(hr)) { throw new ShellException(hr); } // Process the deleted items IEnumerable removedItemsArray = ProcessDeletedItems((IObjectArray)removedItems); // Raise the event if items were removed if (JumpListItemsRemoved != null && removedItemsArray != null && removedItemsArray.GetEnumerator().MoveNext()) { JumpListItemsRemoved(this, new UserRemovedJumpListItemsEventArgs(removedItemsArray)); } }
internal static IntPtr PidlFromUnknown(IntPtr unknown) { IntPtr pidl; int retCode = ShellNativeMethods.SHGetIDListFromObject(unknown, out pidl); return(CoreErrorHelper.Succeeded(retCode) ? pidl : IntPtr.Zero); }
private static void ShowManageLibraryUI(ShellLibrary shellLibrary, IntPtr windowHandle, string title, string instruction, bool allowAllLocations) { int hr = 0; Thread staWorker = new Thread(() => { hr = ShellNativeMethods.SHShowManageLibraryUI( shellLibrary.NativeShellItem, windowHandle, title, instruction, allowAllLocations ? ShellNativeMethods.LibraryManageDialogOptions.NonIndexableLocationWarning : ShellNativeMethods.LibraryManageDialogOptions.Default); }); staWorker.SetApartmentState(ApartmentState.STA); staWorker.Start(); staWorker.Join(); if (!CoreErrorHelper.Succeeded(hr)) { throw new ShellException(hr); } }
/// <summary> /// Creates a condition node that is a logical negation (NOT) of another condition /// (a subnode of this node). /// </summary> /// <param name="conditionToBeNegated">SearchCondition node to be negated.</param> /// <param name="simplify">True to logically simplify the result if possible; False otherwise. /// In a query builder scenario, simplyfy should typically be set to false.</param> /// <returns>New SearchCondition</returns> public static SearchCondition CreateNotCondition(SearchCondition conditionToBeNegated, bool simplify) { if (conditionToBeNegated == null) { throw new ArgumentNullException(nameof(conditionToBeNegated)); } // Same as the native "IConditionFactory:MakeNot" method IConditionFactory nativeConditionFactory = (IConditionFactory) new ConditionFactoryCoClass(); ICondition result; try { HResult hr = nativeConditionFactory.MakeNot(conditionToBeNegated.NativeSearchCondition, simplify, out result); if (!CoreErrorHelper.Succeeded(hr)) { throw new ShellException(hr); } } finally { if (nativeConditionFactory != null) { Marshal.ReleaseComObject(nativeConditionFactory); } } return(new SearchCondition(result)); }
/// <summary> /// Creates a condition node that is a logical conjunction ("AND") or disjunction ("OR") /// of a collection of subconditions. /// </summary> /// <param name="conditionType">The SearchConditionType of the condition node. /// Must be either AndCondition or OrCondition.</param> /// <param name="simplyfy">TRUE to logically simplify the result, if possible; /// then the result will not necessarily to be of the specified kind. FALSE if the result should /// have exactly the prescribed structure. An application that plans to execute a query based on the /// condition tree would typically benefit from setting this parameter to TRUE. </param> /// <param name="conditionNodes">Array of subconditions</param> /// <returns>New SearchCondition based on the operation</returns> public static SearchCondition CreateAndOrCondition(SearchConditionType conditionType, bool simplyfy, params SearchCondition[] conditionNodes) { // Same as the native "IConditionFactory:MakeAndOr" method IConditionFactory nativeConditionFactory = (IConditionFactory) new ConditionFactoryCoClass(); ICondition result = null; try { // List <ICondition> conditionList = new List <ICondition>(); foreach (SearchCondition c in conditionNodes) { conditionList.Add(c.NativeSearchCondition); } IEnumUnknown subConditions = new EnumUnknownClass(conditionList.ToArray()); HRESULT hr = nativeConditionFactory.MakeAndOr(conditionType, subConditions, simplyfy, out result); if (!CoreErrorHelper.Succeeded((int)hr)) { Marshal.ThrowExceptionForHR((int)hr); } } finally { if (nativeConditionFactory != null) { Marshal.ReleaseComObject(nativeConditionFactory); } } return(new SearchCondition(result)); }
/// <summary> /// Adds a location (folder, library, search connector, known folder) to the list of /// places available for the user to open or save items. This method actually adds an item /// to the <b>Favorite Links</b> or <b>Places</b> section of the Open/Save dialog. Overload method /// takes in a string for the path. /// </summary> /// <param name="path">The item to add to the places list.</param> /// <param name="location">One of the enumeration values that indicates placement of the item in the list.</param> public void AddPlace(string path, FileDialogAddPlaceLocation location) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } // Get our native dialog if (nativeDialog == null) { InitializeNativeFileDialog(); nativeDialog = GetNativeFileDialog(); } // Create a native shellitem from our path IShellItem2 nativeShellItem; Guid guid = new Guid(ShellIIDGuid.IShellItem2); int retCode = ShellNativeMethods.SHCreateItemFromParsingName(path, IntPtr.Zero, ref guid, out nativeShellItem); if (!CoreErrorHelper.Succeeded(retCode)) { throw new Exception(LocalizedMessages.CommonFileDialogCannotCreateShellItem, Marshal.GetExceptionForHR(retCode)); } // Add the shellitem to the places list if (nativeDialog != null) { nativeDialog.AddPlace(nativeShellItem, (ShellNativeMethods.FileDialogAddPlacement)location); } }
/// <summary> /// Writes the given property key and value. To allow truncation of the given value, set allowTruncatedValue /// to true. /// </summary> /// <param name="key">The property key.</param> /// <param name="value">The value associated with the key.</param> /// <param name="allowTruncatedValue">True to allow truncation (default); otherwise False.</param> /// <exception cref="System.InvalidOperationException">If the writable property store is already /// closed.</exception> /// <exception cref="System.ArgumentOutOfRangeException">If AllowTruncatedValue is set to false /// and while setting the value on the property it had to be truncated in a string or rounded in /// a numeric value.</exception> public void WriteProperty(PropertyKey key, object value, bool allowTruncatedValue) { if (writablePropStore == null) { throw new InvalidOperationException("Writeable store has been closed."); } using (PropVariant propVar = PropVariant.FromObject(value)) { HResult result = writablePropStore.SetValue(ref key, propVar); if (!allowTruncatedValue && ((int)result == ShellNativeMethods.InPlaceStringTruncated)) { // At this point we can't revert back the commit // so don't commit, close the property store and throw an exception // to let the user know. Marshal.ReleaseComObject(writablePropStore); writablePropStore = null; throw new ArgumentOutOfRangeException("value", LocalizedMessages.ShellPropertyValueTruncated); } if (!CoreErrorHelper.Succeeded(result)) { throw new PropertySystemException(LocalizedMessages.ShellPropertySetValue, Marshal.GetExceptionForHR((int)result)); } } }
/// <summary> /// Given a native KnownFolder (IKnownFolderNative), create the right type of /// IKnownFolder object (FileSystemKnownFolder or NonFileSystemKnownFolder) /// </summary> /// <param name="knownFolderNative">Native Known Folder</param> /// <returns></returns> private static IKnownFolder GetKnownFolder(IKnownFolderNative knownFolderNative) { Debug.Assert(knownFolderNative != null, "Native IKnownFolder should not be null."); // Get the native IShellItem2 from the native IKnownFolder Guid guid = new Guid(ShellIIDGuid.IShellItem2); HResult hr = knownFolderNative.GetShellItem(0, ref guid, out var shellItem); if (!CoreErrorHelper.Succeeded(hr)) { return(null); } bool isFileSystem = false; // If we have a valid IShellItem, try to get the FileSystem attribute. if (shellItem != null) { shellItem.GetAttributes(ShellNativeMethods.ShellFileGetAttributesOptions.FileSystem, out var sfgao); // Is this item a FileSystem item? isFileSystem = (sfgao & ShellNativeMethods.ShellFileGetAttributesOptions.FileSystem) != 0; } // If it's FileSystem, create a FileSystemKnownFolder, else NonFileSystemKnownFolder if (isFileSystem) { FileSystemKnownFolder kf = new FileSystemKnownFolder(knownFolderNative); return(kf); } NonFileSystemKnownFolder knownFsFolder = new NonFileSystemKnownFolder(knownFolderNative); return(knownFsFolder); }
private List <ShellFileSystemFolder> GetFolders() { List <ShellFileSystemFolder> list = new List <ShellFileSystemFolder>(); IShellItemArray itemArray; Guid shellItemArrayGuid = new Guid(ShellIIDGuid.IShellItemArray); HRESULT hr = nativeShellLibrary.GetFolders(ShellNativeMethods.LIBRARYFOLDERFILTER.LFF_ALLITEMS, ref shellItemArrayGuid, out itemArray); if (!CoreErrorHelper.Succeeded((int)hr)) { return(list); } uint count; itemArray.GetCount(out count); for (uint i = 0; i < count; ++i) { IShellItem shellItem; itemArray.GetItemAt(i, out shellItem); list.Add(new ShellFileSystemFolder(shellItem as IShellItem2)); } if (itemArray != null) { Marshal.ReleaseComObject(itemArray); itemArray = null; } return(list); }
internal ShellPropertyWriter(ShellObject parent) { ParentShellObject = parent; // Open the property store for this shell object... Guid guid = new Guid(ShellIIDGuid.IPropertyStore); try { int hr = ParentShellObject.NativeShellItem2.GetPropertyStore( ShellNativeMethods.GetPropertyStoreOptions.ReadWrite, ref guid, out writablePropStore); if (!CoreErrorHelper.Succeeded(hr)) { throw new PropertySystemException(LocalizedMessages.ShellPropertyUnableToGetWritableProperty, Marshal.GetExceptionForHR(hr)); } else { // If we succeed in creating a valid property store for this ShellObject, // then set it on the parent shell object for others to use. // Once this writer is closed/commited, we will set the if (ParentShellObject.NativePropertyStore == null) { ParentShellObject.NativePropertyStore = writablePropStore; } } } catch (InvalidComObjectException e) { throw new PropertySystemException(LocalizedMessages.ShellPropertyUnableToGetWritableProperty, e); } catch (InvalidCastException) { throw new PropertySystemException(LocalizedMessages.ShellPropertyUnableToGetWritableProperty); } }
private static void ShowManageLibraryUI(ShellLibrary shellLibrary, IntPtr windowHandle, string title, string instruction, bool allowAllLocations) { int hr = 0; Thread staWorker = new Thread(() => { hr = ShellNativeMethods.SHShowManageLibraryUI( shellLibrary.NativeShellItem, windowHandle, title, instruction, allowAllLocations ? ShellNativeMethods.LIBRARYMANAGEDIALOGOPTIONS.LMD_NOUNINDEXABLELOCATIONWARNING : ShellNativeMethods.LIBRARYMANAGEDIALOGOPTIONS.LMD_DEFAULT); }); staWorker.SetApartmentState(ApartmentState.STA); staWorker.Start(); staWorker.Join(); if (!CoreErrorHelper.Succeeded(hr)) { Marshal.ThrowExceptionForHR(hr); } }
/// <summary>Returns a formatted, Unicode string representation of a property value.</summary> /// <param name="format">One or more of the PropertyDescriptionFormat flags that indicate the desired format.</param> /// <param name="formattedString">The formatted value as a string, or null if this property cannot be formatted for display.</param> /// <returns>True if the method successfully locates the formatted string; otherwise False.</returns> public bool TryFormatForDisplay(PropertyDescriptionFormatOptions format, out string formattedString) { if (Description == null || Description.NativePropertyDescription == null) { // We cannot do anything without a property description formattedString = null; return(false); } var store = ShellPropertyCollection.CreateDefaultPropertyStore(ParentShellObject); using (var propVar = new PropVariant()) { store.GetValue(ref propertyKey, propVar); // Release the Propertystore Marshal.ReleaseComObject(store); store = null; var hr = Description.NativePropertyDescription.FormatForDisplay(propVar, ref format, out formattedString); // Sometimes, the value cannot be displayed properly, such as for blobs or if we get argument exception if (!CoreErrorHelper.Succeeded(hr)) { formattedString = null; return(false); } return(true); } }
/// <summary> /// Retrieves information about an object in the file system, such as a file, folder, directory, or drive root and a value that indicates the exe type. /// </summary> /// <param name="path"><para>A string of maximum length <see cref="MaxPath"/> that contains the path and file name. Both absolute and relative paths are valid.</para> /// <para>If the <b>uFlags</b> parameter includes the <see cref="GetFileInfoOptions.PIDL"/> flag, this parameter must be the address of an ITEMIDLIST(PIDL) structure that contains the list of item identifiers that uniquely identifies the file within the Shell's namespace. The PIDL must be a fully qualified PIDL. Relative PIDLs are not allowed.</para> /// <para>If the <b>uFlags</b> parameter includes the <see cref="GetFileInfoOptions.UseFileAttributes"/> flag, this parameter does not have to be a valid file name. The function will proceed as if the file exists with the specified name and with the file attributes passed in the <b>dwFileAttributes</b> parameter. This allows you to obtain information about a file type by passing just the extension for <b>pszPath</b> and passing <see cref="FileAttributes.Normal"/> in <b>dwFileAttributes</b>.</para> /// <para>This string can use either short (the 8.3 form) or long file names.</para></param> /// <param name="fileAttributes">A combination of one or more <see cref="FileAttributes"/> flags. If <b>uFlags</b> does not include the <see cref="GetFileInfoOptions.UseFileAttributes"/> flag, this parameter is ignored.</param> /// <param name="options">The flags that specify the file information to retrieve. This parameter can be a combination of the values of the <see cref="GetFileInfoOptions"/> enum.</param> /// <param name="exeType">The exe type. In order to this method retrieves the exe type, you need to use the <see cref="GetFileInfoOptions.ExeType"/> flag in the <b>options</b> parameter.</param> /// <returns>A <see cref="FileInfo"/> structure that contains the file information.</returns> public static FileInfo GetFileInfo(string path, FileAttributes fileAttributes, GetFileInfoOptions options, out int exeType) { var psfi = new SHFILEINFO(); HResult hr = SHGetFileInfo(path, fileAttributes, ref psfi, (uint)Marshal.SizeOf(psfi), options); if (!CoreErrorHelper.Succeeded(hr)) { Marshal.ThrowExceptionForHR((int)hr); } exeType = options.HasFlag(GetFileInfoOptions.ExeType) ? (int)hr : 0; Icon icon; if (psfi.hIcon == IntPtr.Zero) { icon = null; } else { icon = (Icon)Icon.FromHandle(psfi.hIcon).Clone(); _ = Core.DestroyIcon(psfi.hIcon); } return(new FileInfo(icon, psfi.iIcon, psfi.dwAttributes, psfi.szDisplayName, psfi.szTypeName)); }
internal SearchCondition(ICondition nativeSearchCondition) { if (nativeSearchCondition == null) { throw new ArgumentNullException("nativeSearchCondition"); } NativeSearchCondition = nativeSearchCondition; HResult hr = NativeSearchCondition.GetConditionType(out conditionType); if (!CoreErrorHelper.Succeeded(hr)) { throw new ShellException(hr); } if (ConditionType == SearchConditionType.Leaf) { using (PropVariant propVar = new PropVariant()) { hr = NativeSearchCondition.GetComparisonInfo(out canonicalName, out conditionOperation, propVar); if (!CoreErrorHelper.Succeeded(hr)) { throw new ShellException(hr); } PropertyValue = propVar.Value.ToString(); } } }
/// <summary> /// Returns a formatted, Unicode string representation of a property value. /// </summary> /// <param name="format">One or more of the PropertyDescriptionFormat flags /// that indicate the desired format.</param> /// <returns>The formatted value as a string, or null if this property /// cannot be formatted for display.</returns> public string FormatForDisplay(PropertyDescriptionFormatOptions format) { string formattedString; if (Description == null || Description.NativePropertyDescription == null) { // We cannot do anything without a property description return(null); } IPropertyStore store = ShellPropertyCollection.CreateDefaultPropertyStore(ParentShellObject); using (PropVariant propVar = new PropVariant()) { store.GetValue(ref propertyKey, propVar); // Release the Propertystore Marshal.ReleaseComObject(store); store = null; HResult hr = Description.NativePropertyDescription.FormatForDisplay(propVar, ref format, out formattedString); // Sometimes, the value cannot be displayed properly, such as for blobs // or if we get argument exception if (!CoreErrorHelper.Succeeded(hr)) { throw new ShellException(hr); } return(formattedString); } }
/// <summary> /// Writes the given property key and value. To allow truncation of the given value, set allowTruncatedValue /// to true. /// </summary> /// <param name="key">The property key.</param> /// <param name="value">The value associated with the key.</param> /// <param name="allowTruncatedValue">True to allow truncation (default); otherwise False.</param> /// <exception cref="System.InvalidOperationException">If the writable property store is already /// closed.</exception> /// <exception cref="System.ArgumentOutOfRangeException">If AllowTruncatedValue is set to false /// and while setting the value on the property it had to be truncated in a string or rounded in /// a numeric value.</exception> public void WriteProperty(PropertyKey key, object value, bool allowTruncatedValue) { if (writablePropStore == null) { throw new InvalidOperationException("Writeable store has been closed."); } PropVariant propVar = PropVariant.FromObject(value); int result = writablePropStore.SetValue(ref key, ref propVar); if (!allowTruncatedValue && (result == InPlaceStringTruncated)) { // At this point we can't revert back the commit // so don't commit, close the property store and throw an exception // to let the user know. Marshal.ReleaseComObject(writablePropStore); writablePropStore = null; throw new ArgumentOutOfRangeException("value", "A value had to be truncated in a string or rounded if a numeric value. Set AllowTruncatedValue to true to prevent this exception."); } if (!CoreErrorHelper.Succeeded(result)) { throw new ExternalException("Unable to set property.", Marshal.GetExceptionForHR(result)); } }
/// <summary> /// Creates a list of stack keys, as specified. If this method is not called, /// by default the folder will not be stacked. /// </summary> /// <param name="canonicalNames">Array of canonical names for properties on which the folder is stacked.</param> /// <exception cref="System.ArgumentException">If one of the given canonical names is invalid.</exception> public void SetStacks(params string[] canonicalNames) { if (canonicalNames == null) { throw new ArgumentNullException("canonicalNames"); } List <PropertyKey> propertyKeyList = new List <PropertyKey>(); foreach (string prop in canonicalNames) { // Get the PropertyKey using the canonicalName passed in PropertyKey propKey; int result = PropertySystemNativeMethods.PSGetPropertyKeyFromName(prop, out propKey); if (!CoreErrorHelper.Succeeded(result)) { throw new ArgumentException(LocalizedMessages.ShellInvalidCanonicalName, "canonicalNames", Marshal.GetExceptionForHR(result)); } propertyKeyList.Add(propKey); } if (propertyKeyList.Count > 0) { SetStacks(propertyKeyList.ToArray()); } }
/// <summary> /// Creates a condition node that is a logical negation (NOT) of another condition /// (a subnode of this node). /// </summary> /// <param name="conditionToBeNegated">SearchCondition node to be negated.</param> /// <param name="simplyfy">True to logically simplify the result if possible; False otherwise. /// In a query builder scenario, simplyfy should typically be set to false.</param> /// <returns>New SearchCondition</returns> public static SearchCondition CreateNotCondition(SearchCondition conditionToBeNegated, bool simplyfy) { // Same as the native "IConditionFactory:MakeNot" method IConditionFactory nativeConditionFactory = (IConditionFactory) new ConditionFactoryCoClass(); ICondition result; try { HRESULT hr = nativeConditionFactory.MakeNot(conditionToBeNegated.NativeSearchCondition, simplyfy, out result); if (!CoreErrorHelper.Succeeded((int)hr)) { Marshal.ThrowExceptionForHR((int)hr); } } finally { if (nativeConditionFactory != null) { Marshal.ReleaseComObject(nativeConditionFactory); } } return(new SearchCondition(result)); }
/// <summary> /// Load the library using a number of options /// </summary> /// <param name="libraryName">The name of the library</param> /// <param name="isReadOnly">If <B>true</B>, loads the library in read-only mode.</param> /// <returns>A ShellLibrary Object</returns> public static ShellLibrary Load(string libraryName, bool isReadOnly) { CoreHelpers.ThrowIfNotWin7(); IKnownFolder kf = KnownFolders.Libraries; string librariesFolderPath = (kf != null) ? kf.Path : string.Empty; Guid guid = new Guid(ShellIIDGuid.IShellItem); string shellItemPath = System.IO.Path.Combine(librariesFolderPath, libraryName + FileExtension); int hr = ShellNativeMethods.SHCreateItemFromParsingName(shellItemPath, IntPtr.Zero, ref guid, out IShellItem nativeShellItem); if (!CoreErrorHelper.Succeeded(hr)) { throw new ShellException(hr); } INativeShellLibrary nativeShellLibrary = (INativeShellLibrary) new ShellLibraryCoClass(); AccessModes flags = isReadOnly ? AccessModes.Read : AccessModes.ReadWrite; nativeShellLibrary.LoadLibraryFromItem(nativeShellItem, flags); ShellLibrary library = new ShellLibrary(nativeShellLibrary); try { library.nativeShellItem = (IShellItem2)nativeShellItem; library.Name = libraryName; return(library); } catch { library.Dispose(); throw; } }
/// <summary> /// Registers an application for recovery by Application Restart and Recovery. /// </summary> /// <param name="settings">An object that specifies /// the callback method, an optional parameter to pass to the callback /// method and a time interval.</param> /// <exception cref="System.ArgumentException"> /// The registration failed due to an invalid parameter. /// </exception> /// <exception cref="System.ComponentModel.Win32Exception"> /// The registration failed.</exception> /// <remarks>The time interval is the period of time within /// which the recovery callback method /// calls the <see cref="ApplicationRecoveryInProgress"/> method to indicate /// that it is still performing recovery work.</remarks> public static void RegisterForApplicationRecovery(RecoverySettings settings) { // Throw PlatformNotSupportedException if the user is not running Vista or beyond CoreHelpers.ThrowIfNotVista(); if (settings == null) { throw new ArgumentNullException("settings"); } GCHandle handle = GCHandle.Alloc(settings.RecoveryData); HRESULT hr = AppRestartRecoveryNativeMethods.RegisterApplicationRecoveryCallback(AppRestartRecoveryNativeMethods.internalCallback, (IntPtr)handle, settings.PingInterval, (uint)0); if (!CoreErrorHelper.Succeeded((int)hr)) { if (hr == HRESULT.E_INVALIDARG) { throw new ArgumentException("Application was not registered for recovery due to bad parameters."); } else { throw new ExternalException("Application failed to register for recovery."); } } }
private List <ShellFileSystemFolder> GetFolders() { List <ShellFileSystemFolder> list = new List <ShellFileSystemFolder>(); Guid shellItemArrayGuid = new Guid(ShellIIDGuid.IShellItemArray); HResult hr = nativeShellLibrary.GetFolders(ShellNativeMethods.LibraryFolderFilter.AllItems, ref shellItemArrayGuid, out var itemArray); if (!CoreErrorHelper.Succeeded(hr)) { return(list); } itemArray.GetCount(out var count); for (uint i = 0; i < count; ++i) { itemArray.GetItemAt(i, out var shellItem); list.Add(new ShellFileSystemFolder(shellItem as IShellItem2)); } if (itemArray != null) { Marshal.ReleaseComObject(itemArray); itemArray = null; } return(list); }
internal static IntPtr PidlFromParsingName(string name) { var retCode = ShellNativeMethods.SHParseDisplayName( name, IntPtr.Zero, out var pidl, 0, out var sfgao); return(CoreErrorHelper.Succeeded(retCode) ? pidl : IntPtr.Zero); }
/// <summary> /// Sets the search folder display name. /// </summary> public void SetDisplayName(string displayName) { HResult hr = NativeSearchFolderItemFactory.SetDisplayName(displayName); if (!CoreErrorHelper.Succeeded(hr)) { throw new ShellException(hr); } }
/// <summary> /// Creates a list of sort column directions, as specified. /// </summary> /// <remarks>This property may not work correctly with the ExplorerBrowser control.</remarks> public void SortColumns(SortColumn[] value) { HResult hr = NativeSearchFolderItemFactory.SetSortColumns(value == null ? 0 : (uint)value.Length, value); if (!CoreErrorHelper.Succeeded(hr)) { throw new ShellException(LocalizedMessages.ShellSearchFolderUnableToSetSortColumns, Marshal.GetExceptionForHR((int)hr)); } }
/// <summary> /// Sets the search folder icon size. /// The default settings are based on the FolderTypeID which is set by the /// SearchFolder::SetFolderTypeID method. /// </summary> public void SetIconSize(int value) { HResult hr = NativeSearchFolderItemFactory.SetIconSize(value); if (!CoreErrorHelper.Succeeded(hr)) { throw new ShellException(hr); } }
internal static IntPtr PidlFromShellItem(IShellItem nativeShellItem) { IntPtr shellItem = Marshal.GetComInterfaceForObject(nativeShellItem, typeof(IShellItem)); IntPtr pidl; int retCode = ShellNativeMethods.SHGetIDListFromObject(shellItem, out pidl); return(CoreErrorHelper.Succeeded(retCode) ? pidl : IntPtr.Zero); }
/// <summary> /// Sets a search folder type ID, as specified. /// </summary> public void SetFolderTypeID(Guid value) { HResult hr = NativeSearchFolderItemFactory.SetFolderTypeID(value); if (!CoreErrorHelper.Succeeded(hr)) { throw new ShellException(hr); } }
/// <summary> /// Sets folder logical view mode. The default settings are based on the FolderTypeID which is set /// by the SearchFolder::SetFolderTypeID method. /// </summary> /// <param name="mode">The logical view mode to set.</param> public void SetFolderLogicalViewMode(FolderLogicalViewMode mode) { HResult hr = NativeSearchFolderItemFactory.SetFolderLogicalViewMode(mode); if (!CoreErrorHelper.Succeeded(hr)) { throw new ShellException(hr); } }
/// <summary> /// Sets a group column, as specified. If no group column is specified, no grouping occurs. /// </summary> /// <remarks>This property may not work correctly with the ExplorerBrowser control.</remarks> public void SetGroupColumn(PropertyKey propertyKey) { HResult hr = NativeSearchFolderItemFactory.SetGroupColumn(ref propertyKey); if (!CoreErrorHelper.Succeeded(hr)) { throw new ShellException(hr); } }