/// <summary> /// This method will fill a TreeNode with the folders from it's ShellItem /// </summary> /// <param name="node">The TreeNode to extend</param> private bool ExtendTreeNode(TreeNode node, bool overwrite, IntPtr handle) { if (overwrite || !IsExtended(node)) { ShellItem nodeItem = (ShellItem)node.Tag; ShellBrowser.UpdateCondition.ContinueUpdate = false; if (nodeItem.Expand(false, true, handle)) { folderView.BeginUpdate(); node.Nodes.Clear(); TreeNode[] newNodesArray = new TreeNode[nodeItem.SubFolders.Count]; for (int i = 0; i < newNodesArray.Length; i++) { newNodesArray[i] = new TreeNode( nodeItem.SubFolders[i].Text, nodeItem.SubFolders[i].ImageIndex, nodeItem.SubFolders[i].SelectedImageIndex); newNodesArray[i].Tag = nodeItem.SubFolders[i]; if (nodeItem.SubFolders[i].HasSubfolder) { newNodesArray[i].Nodes.Add(string.Empty); } newNodesArray[i].Name = newNodesArray[i].Text; } node.Nodes.AddRange(newNodesArray); folderView.EndUpdate(); return(true); } else { return(false); } } else { return(true); } }
private void InitVars() { IntPtr tempPidl; ShellAPI.SHFILEINFO info; //My Computer info = new ShellAPI.SHFILEINFO(); tempPidl = IntPtr.Zero; ShellAPI.SHGetSpecialFolderLocation(IntPtr.Zero, ShellAPI.CSIDL.DRIVES, out tempPidl); ShellAPI.SHGetFileInfo(tempPidl, 0, ref info, ShellAPI.cbFileInfo, ShellAPI.SHGFI.PIDL | ShellAPI.SHGFI.DISPLAYNAME | ShellAPI.SHGFI.TYPENAME); sysfolderName = info.szTypeName; mycompName = info.szDisplayName; Marshal.FreeCoTaskMem(tempPidl); // //Dekstop tempPidl = IntPtr.Zero; desktopItem = new ShellItem(this, ShellAPI.CSIDL.DESKTOP); desktopItem.Expand(true, true, IntPtr.Zero); // myComputerItem = desktopItem.SubFolders[MyComputerName]; //My Documents uint pchEaten = 0; ShellAPI.SFGAO pdwAttributes = 0; desktopItem.ShellFolder.ParseDisplayName( IntPtr.Zero, IntPtr.Zero, "::{450d8fba-ad25-11d0-98a8-0800361b1103}", ref pchEaten, out tempPidl, ref pdwAttributes); info = new ShellAPI.SHFILEINFO(); ShellAPI.SHGetFileInfo(tempPidl, 0, ref info, ShellAPI.cbFileInfo, ShellAPI.SHGFI.PIDL | ShellAPI.SHGFI.DISPLAYNAME); mydocsName = info.szDisplayName; Marshal.FreeCoTaskMem(tempPidl); StringBuilder path = new StringBuilder(ShellAPI.MAX_PATH); ShellAPI.SHGetFolderPath( IntPtr.Zero, ShellAPI.CSIDL.PERSONAL, IntPtr.Zero, ShellAPI.SHGFP.TYPE_CURRENT, path); mydocsPath = path.ToString(); // pchEaten = 0; pdwAttributes = 0; desktopItem.ShellFolder.ParseDisplayName( IntPtr.Zero, IntPtr.Zero, "::{645FF040-5081-101B-9F08-00AA002F954E}", ref pchEaten, out tempPidl, ref pdwAttributes); info = new ShellAPI.SHFILEINFO(); ShellAPI.SHGetFileInfo(tempPidl, 0, ref info, ShellAPI.cbFileInfo, ShellAPI.SHGFI.PIDL | ShellAPI.SHGFI.DISPLAYNAME); recycleBinName = info.szDisplayName; Marshal.FreeCoTaskMem(tempPidl); }