public static string GetRealPath(ShellItem item) { if(item.Equals(item.browser.DesktopItem)) { return "::{450d8fba-ad25-11d0-98a8-0800361b1103}"; } else if(item.Type == item.Browser.SystemFolderName) { IntPtr strr = Marshal.AllocCoTaskMem(ShellAPI.MAX_PATH * 2 + 4); Marshal.WriteInt32(strr, 0, 0); StringBuilder buf = new StringBuilder(ShellAPI.MAX_PATH); if(item.ParentItem.ShellFolder.GetDisplayNameOf( item.PIDLRel.Ptr, ShellAPI.SHGNO.FORPARSING, strr) == ShellAPI.S_OK) { ShellAPI.StrRetToBuf(strr, item.PIDLRel.Ptr, buf, ShellAPI.MAX_PATH); } Marshal.FreeCoTaskMem(strr); return buf.ToString(); } else return item.Path; }
/// <summary> /// When a new directory is selected, this method is called to clear the ListView and fill it with /// the contents of the new directory /// </summary> /// <param name="oldItem">The ShellItem of the previous selected directory</param> /// <param name="newItem">The ShellItem of the new selected directory</param> private bool SetNewPath(ShellItem oldItem, ShellItem newItem) { Cursor.Current = Cursors.WaitCursor; if (oldItem != newItem && newItem.Expand(true, false, Handle)) { ShellBrowser.UpdateCondition.ContinueUpdate = false; fileView.BeginUpdate(); fileView.Items.Clear(); fileView.ClearSelections(); if (oldItem != null) { bool used = false; foreach (Browser br in ShellBrowser.Browsers) { if (!this.Equals(br) && oldItem.Equals(br.SelectedItem)) { used = true; break; } } if (!used) oldItem.Clear(true, false); } selectedItem = newItem; ListViewItem[] newListItemsArray = new ListViewItem[newItem.Count]; string[] subItems = new string[fileView.Columns.Count - 1]; for (int i = 0; i < newListItemsArray.Length; i++) { newListItemsArray[i] = GetListViewItem(subItems, newItem[i]); } fileView.SetSorting(true); fileView.Items.AddRange(newListItemsArray); fileView.SetSorting(false); fileView.EndUpdate(); Cursor.Current = Cursors.Default; return true; } else { Cursor.Current = Cursors.Default; return (oldItem == newItem); } }
public bool GetListItem(ShellItem shellItem, out ListViewItem listItem) { listItem = null; foreach (ListViewItem item in Items) { if (shellItem.Equals(item.Tag)) { listItem = item; return true; } } return false; }