/// <summary> /// Creates a ShellObject collection from an IShellItemArray /// </summary> /// <param name="iArray">IShellItemArray pointer</param> /// <param name="readOnly">Indicates whether the collection shouldbe read-only or not</param> internal ShellObjectCollection(IShellItemArray iArray, bool readOnly) { this.readOnly = readOnly; if (iArray != null) { try { uint itemCount = 0; iArray.GetCount(out itemCount); content = new List <ShellObject>((int)itemCount); for (uint index = 0; index < itemCount; index++) { IShellItem iShellItem = null; iArray.GetItemAt(index, out iShellItem); content.Add(ShellObjectFactory.Create(iShellItem)); } } finally { Marshal.ReleaseComObject(iArray); } } }
internal IShellItem GetShellItemAt(IShellItemArray array, int i) { uint index = (uint)i; array.GetItemAt(index, out IShellItem result); return(result); }
/// <summary> /// シェルアイテム配列の各アイテムのファイルパスを列挙する /// </summary> /// <param name="items">シェルアイテム配列</param> /// <returns>ファイルパスのシーケンス</returns> public static IEnumerable <string> EnumerateItemPaths(IShellItemArray items) { // 配列内アイテムの個数を取得 items.GetCount(out var itemCount); // 各アイテムからパスを取得 for (uint i = 0; i < itemCount; i++) { var item = default(IShellItem); var path = default(string); try { // 配列内のシェルアイテム取得 items.GetItemAt(i, out item); // アイテムのパスを取得 path = GetFileSystemPath(item); } finally { // シェルアイテムの参照を解放 ReleaseExistComObject(item); } // パスを列挙 yield return(path); } }
public static String[] GetFileNames(IShellItemArray items) { UInt32 count; HResult hresult = items.GetCount(out count); if (hresult != HResult.Ok) { throw new InvalidOperationException("IShellItemArray.GetCount failed. HResult: " + hresult); } String[] fileNames = new String[count]; for (UInt32 i = 0; i < count; i++) { HResult result = items.GetItemAt(i, out IShellItem shellItem); if (result != HResult.Ok) { throw new InvalidOperationException("IShellItemArray.GetItemAt( " + i + " ) failed. HResult: " + hresult); } String fileName = Utility.GetFileNameFromShellItem(shellItem); fileNames[i] = fileName; } return(fileNames); }
internal static IShellItem GetShellItemAt(IShellItemArray array, int i) { IShellItem result; uint index = (uint)i; array.GetItemAt(index, out result); return result; }
static internal IShellItem GetShellItemAt(IShellItemArray array, int i) { IShellItem result; var index = (uint)i; array.GetItemAt(index, out result); return(result); }
public static void PrintShellItemArray(IShellItemArray shellItemArray) { for (uint i = 0; i < shellItemArray.GetCount(); i++) { IShellItem si = shellItemArray.GetItemAt(i); Console.Out.WriteLine(si.GetDisplayName(SIGDN.SIGDN_FILESYSPATH)); Marshal.ReleaseComObject(si); } }
/// <summary> /// Get <see cref="IShellItem" /> at the position specified by <see cref="index" /> /// from <see cref="IShellItemArray" />. /// </summary> /// <param name="shellItemArray"><see cref="IShellItemArray" />.</param> /// <param name="index">Index of the <see cref="IShellItemArray" />.</param> /// <returns><see cref="IShellItem" />.</returns> internal static IShellItem GetShellItemAt(IShellItemArray shellItemArray, int index) { Contract.Requires <ArgumentNullException>(shellItemArray != null); IShellItem result; shellItemArray.GetItemAt((uint)index, out result); return(result); }
public static HRESULT DisplayItem(this IShellItemArray psia, HWND hwnd = default) { // Get the first ShellItem and display its name IShellItem psi = psia.GetItemAt(0); var pszDisplayName = psi.GetDisplayName(SIGDN.SIGDN_NORMALDISPLAY); User32.MessageBox(hwnd, pszDisplayName, pszDisplayName, User32.MB_FLAGS.MB_OK); return(HRESULT.S_OK); }
private static IEnumerable <string> ConvertShellItemArray(IShellItemArray itemArray) { itemArray.GetCount(out var count); string[] paths = new string[count]; for (int i = 0; i < count; i++) { itemArray.GetItemAt(i, out IShellItem item); item.GetDisplayName(SIGDN.FILESYSPATH, out var name); paths[i] = name; } return(paths); }
public static IShellItem GetShellItemAt(IShellItemArray array, int i) #endif { if (array is null) { throw new ArgumentNullException(nameof(array)); } HResult hr = array.GetItemAt((UInt32)i, out IShellItem result); if (hr == HResult.Ok) { return(result); } else { return(null); } }
internal override string[] ProcessVistaFiles(IFileDialog dialog) { var openDialog = (IFileOpenDialog)dialog; if (Multiselect) { IShellItemArray results = openDialog.GetResults(); uint count = results.GetCount(); string[] paths = new string[count]; for (uint i = 0; i < count; ++i) { IShellItem item = results.GetItemAt(i); paths[i] = item.GetDisplayName(SIGDN.DESKTOPABSOLUTEPARSING); } return paths; } else { IShellItem item = openDialog.GetResult(); return new [] { item.GetDisplayName(SIGDN.DESKTOPABSOLUTEPARSING) }; } }
/// <summary> /// Converts an <see cref="IShellItemArray"/> into a IShellItem[] /// </summary> /// <param name="shellItemArray">The Interface you want to convert</param> /// <returns></returns> public static IShellItem[] ToArray(this IShellItemArray shellItemArray) { var items = new List <IShellItem>(); if (shellItemArray == null) { return(items.ToArray()); } try { uint itemCount = 0; shellItemArray.GetCount(out itemCount); for (uint index = 0; index < itemCount; index++) { IShellItem iShellItem = null; shellItemArray.GetItemAt(index, out iShellItem); items.Add(iShellItem); } } finally { //Marshal.ReleaseComObject(shellItemArray); } return(items.ToArray()); }
/// <summary>Creates a ShellObject collection from an IShellItemArray</summary> /// <param name="iArray">IShellItemArray pointer</param> /// <param name="readOnly">Indicates whether the collection shouldbe read-only or not</param> internal ShellObjectCollection(IShellItemArray iArray, bool readOnly) { this.readOnly = readOnly; if (iArray != null) { try { iArray.GetCount(out var itemCount); content.Capacity = (int)itemCount; for (uint index = 0; index < itemCount; index++) { iArray.GetItemAt(index, out var iShellItem); content.Add(ShellObjectFactory.Create(iShellItem)); } } finally { Marshal.ReleaseComObject(iArray); } } }
/// <summary>Gets the <see cref="ShellItem"/> at the specified index.</summary> /// <value>The <see cref="ShellItem"/>.</value> /// <param name="index">The zero-based index of the element to get.</param> public ShellItem this[int index] { get { IShellItemArray array = Array; try { return(array is null ? null : ShellItem.Open(array.GetItemAt((uint)index))); } catch { return(null); } finally { if (array is not null) { Marshal.ReleaseComObject(array); } } } }
internal override string[] ProcessVistaFiles(IFileDialog dialog) { IFileOpenDialog fileOpenDialog = (IFileOpenDialog)dialog; if (this.Multiselect) { IShellItemArray results = fileOpenDialog.GetResults(); uint count = results.GetCount(); string[] array = new string[count]; for (uint num = 0U; num < count; num += 1U) { IShellItem itemAt = results.GetItemAt(num); array[(int)num] = itemAt.GetDisplayName((SIGDN)2147647488U); } return(array); } IShellItem result = fileOpenDialog.GetResult(); return(new string[] { result.GetDisplayName((SIGDN)2147647488U) }); }
/// <summary> /// Creates a ShellObject collection from an IShellItemArray /// </summary> /// <param name="iArray">IShellItemArray pointer</param> /// <param name="readOnly">Indicates whether the collection shouldbe read-only or not</param> internal ShellObjectCollection(IShellItemArray iArray, bool readOnly) { IsReadOnly = readOnly; if (iArray != null) { try { Marshal.ThrowExceptionForHR((int)iArray.GetCount(out uint itemCount)); content.Capacity = (int)itemCount; for (uint index = 0; index < itemCount; index++) { Marshal.ThrowExceptionForHR((int)iArray.GetItemAt(index, out IShellItem iShellItem)); content.Add(ShellObjectFactory.Create(iShellItem)); } } finally { _ = Marshal.ReleaseComObject(iArray); } } }
internal IShellItem GetShellItemAt(IShellItemArray array, int i) { IShellItem result; uint index = (uint)i; array.GetItemAt(index, out result); return result; }
/// <summary>Gets the <see cref="ShellItem"/> at the specified index.</summary> /// <value>The <see cref="ShellItem"/>.</value> /// <param name="index">The index.</param> /// <returns>A <see cref="ShellItem"/> instance.</returns> public ShellItem this[int index] => ShellItem.Open(array.GetItemAt((uint)index));