Example #1
0
 /// <summary>
 /// Enumerates all children of this item. If this item is not a folder/container, this method will return an empty enumeration.
 /// </summary>
 /// <param name="filter">A filter for the types of children to enumerate.</param>
 /// <param name="parentWindow">The parent window.</param>
 /// <returns>An enumerated list of children matching the filter.</returns>
 public IEnumerable <ShellItem> EnumerateChildren(FolderItemFilter filter /*= FolderItemFilter.Folders | FolderItemFilter.IncludeHidden | FolderItemFilter.NonFolders | FolderItemFilter.IncludeSuperHidden */, HWND parentWindow = default)
 {
     if (iShellFolder.EnumObjects(parentWindow, (SHCONTF)filter, out var eo).Failed)
     {
         Debug.WriteLine($"Unable to enum children in folder.");
     }
     foreach (var p in eo.Enumerate(20))
     {
         ShellItem i = null;
         try { i = this[p]; } catch (Exception e) { Debug.WriteLine($"Unable to open folder child: {e.Message}"); }
         if (i != null)
         {
             yield return(i);
         }
     }
     Marshal.ReleaseComObject(eo);
 }
Example #2
0
        /// <summary>
        /// Enumerates all children of this item. If this item is not a folder/container, this method will return an empty enumeration.
        /// </summary>
        /// <param name="filter">A filter for the types of children to enumerate.</param>
        /// <param name="parentWindow">The parent window.</param>
        /// <returns>An enumerated list of children matching the filter.</returns>
        public IEnumerable <ShellItem> EnumerateChildren(FolderItemFilter filter /*= FolderItemFilter.Folders | FolderItemFilter.IncludeHidden | FolderItemFilter.NonFolders | FolderItemFilter.IncludeSuperHidden */, System.Windows.Forms.IWin32Window parentWindow = null)
        {
            IEnumIDList eo = null;

            try
            {
                eo = iShellFolder.EnumObjects(IWin2Ptr(parentWindow, false), (SHCONTF)filter);
            }
            catch (Exception e) { Debug.WriteLine($"Unable to enum children in folder: {e.Message}"); }
            foreach (var p in eo.Enumerate(20))
            {
                ShellItem i = null;
                try { i = this[p]; } catch (Exception e) { Debug.WriteLine($"Unable to open folder child: {e.Message}"); }
                if (i != null)
                {
                    yield return(i);
                }
            }
            Marshal.ReleaseComObject(eo);
        }
Example #3
0
        /// <summary>
        /// Enumerates all children of this item. If this item is not a folder/container, this method will return an empty enumeration.
        /// </summary>
        /// <param name="filter">A filter for the types of children to enumerate.</param>
        /// <param name="parentWindow">The parent window.</param>
        /// <returns>An enumerated list of children matching the filter.</returns>
        public IEnumerable <ShellItem> EnumerateChildren(FolderItemFilter filter /*= FolderItemFilter.Folders | FolderItemFilter.IncludeHidden | FolderItemFilter.NonFolders | FolderItemFilter.IncludeSuperHidden */, System.Windows.Forms.IWin32Window parentWindow = null)
        {
            IEnumIDList eo = null;

            try
            {
                eo = iShellFolder.EnumObjects(IWin2Ptr(parentWindow, false), (SHCONTF)filter);
            }
            catch (Exception e) { Debug.WriteLine($"Unable to enum children in folder: {e.Message}"); }
            if (eo != null)
            {
                foreach (var p in new Collections.IEnumFromNext <IntPtr>((out IntPtr p) => eo.Next(1, out p, out var f).Succeeded&& f == 1, () => { try { eo.Reset(); } catch { } }))
                {
                    ShellItem i = null;
                    try { i = this[new PIDL(p)]; } catch (Exception e) { Debug.WriteLine($"Unable to open folder child: {e.Message}"); }
                    if (i != null)
                    {
                        yield return(i);
                    }
                }
                Marshal.ReleaseComObject(eo);
            }
        }
Example #4
0
 /// <summary>Initializes a new instance of the <see cref="ShellDataTable"/> class with the items from a shell folder.</summary>
 /// <param name="folder">The folder whose items are to be retrieved.</param>
 /// <param name="filter">The filter to determine which child items of the folder are enumerated.</param>
 public ShellDataTable(ShellFolder folder, FolderItemFilter filter = FolderItemFilter.Folders | FolderItemFilter.NonFolders) : base(folder.ParsingName)
 {
     itemFilter          = filter;
     BuildColumns(parent = folder);
 }