public void Reload()
 {
     this.TreeView.BeginWaitCursor();
     this.TreeView.SuspendLayout();
     try
     {
         DisposeEach(base.Nodes);
         base.Nodes.Clear();
         foreach (ShellItem shellItem in _shellItem.EnumerateChildren(ShellItem.ChildType.Folders))
         {
             base.Nodes.Add(new FolderTreeNode(shellItem));
         }
     }
     catch (PathNotFoundException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new PathAccessException(_shellItem.Path, ex);
     }
     finally
     {
         this.TreeView.ResumeLayout(true);
         this.TreeView.EndWaitCursor();
     }
 }
Beispiel #2
0
        public bool TryBrowseToVirtualLocation(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                this.BrowseTo((Pidl)null);
                return(true);
            }

            string vRelativePath;

            // try to figure how the virtual path is rooted - if there is no match, assume desktop as root
            Pidl vPathRootPidl = _defaultSearchLocations.FindRoot(path, out vRelativePath) ?? _rootShellItem.Pidl;

            if (string.IsNullOrEmpty(vRelativePath))
            {
                // no umatched path relative to the root, so we can browse there directly
                // this PIDL is either owned by _rootShellItem or _defaultSearchLocations, so we don't need to dispose of it
                this.BrowseTo(vPathRootPidl);
                return(true);
            }

            string vChildComponent;

            // try to find the first matching child of the discovered special path root
            string vFirstComponent = GetPathRoot(vRelativePath, out vChildComponent);

            using (ShellItem vPathRootShellItem = new ShellItem(vPathRootPidl, _rootShellItem, false))
            {
                List <ShellItem> children = new List <ShellItem>(vPathRootShellItem.EnumerateChildren());
                try
                {
                    // find the first child whose display name matches the first component of the desired path
                    foreach (ShellItem child in children)
                    {
                        if (string.Equals(child.DisplayName, vFirstComponent, StringComparison.InvariantCultureIgnoreCase))
                        {
                            // if we have an additional child path component, and this item has a physical path, combine them!
                            if (!string.IsNullOrEmpty(vChildComponent) && !string.IsNullOrEmpty(child.Path))
                            {
                                string fullyQualifiedPath = Path.Combine(child.Path, vChildComponent);
                                using (Pidl pidl = Pidl.Parse(fullyQualifiedPath))
                                {
                                    if (pidl == null)
                                    {
                                        return(false);
                                    }
                                    this.BrowseTo(pidl);
                                    return(true);
                                }
                            }
                            this.BrowseTo(child.Pidl);
                            return(true);
                        }
                    }
                }
                finally
                {
                    // the call to EnumerateChildren() created this items - we must dispose them!
                    foreach (ShellItem child in children)
                    {
                        child.Dispose();
                    }
                }
            }

            return(false);
        }