En el post anterior comentaba como hacer un WebPart  que muestre el árbol de sitios. Para ello se parte del nodo raíz (RootWeb) y se examinaban recursiva mente todos los sub-sitios dibujando en un control ASP.NET TreeView.

Ahora mostrare  otro enfoque que permite pintar el árbol completo de todos los contenidos(incluyendo las listas y bibliotecas).

En realidad lo que se hace es reproducir el funcionamiento del control árbol de navegación lateral de WSS.

14092007_01

El mapa de contenidos se obtiene a partir de SPHierarchyDataSourceControl que es el control que proporciona la vista jerarquizada de los sitios y listas de SharePoint.

Para los experimentos lo práctico es usar las extensiones de SharePoint para VisualStuido tal y como comentaba en el post anterior, el código del WebPart es el siguiente:

using System.Xml.Serialization; using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; using Microsoft.SharePoint.WebPartPages; using Microsoft.SharePoint.Navigation; namespace TreeWebPart { [Guid("9bff5178-c411-4ede-a7fa-42be6d5df451")] public class TreeWebPart : System.Web.UI.WebControls.WebParts.WebPart { public TreeWebPart() { this.ExportMode = WebPartExportMode.All; } private void ListSubWebs(SPWeb Web, TreeNode TreeNode) { TreeNode.Text = Web.Title; TreeNode.NavigateUrl = Web.Url; foreach (SPWeb WWeb in Web.GetSubwebsForCurrentUser()) { TreeNode ContainerNode = new TreeNode(); TreeNode.ChildNodes.Add(ContainerNode); ListSubWebs(WWeb, ContainerNode); } } protected override void CreateChildControls() { base.CreateChildControls(); SPHierarchyDataSourceControl SPHDataSource = new SPHierarchyDataSourceControl(); SPHDataSource.RootContextObject = "Web"; SPHDataSource.ID = "TreeViewDataSource"; SPHDataSource.IncludeDiscussionFolders = true; SPHDataSource.ShowListChildren = true; SPHDataSource.ShowDocLibChildren = true; SPHDataSource.ShowFolderChildren = true; Controls.Add(SPHDataSource); SPTreeView SitesTree = new SPTreeView(); SitesTree.DataSourceID = "TreeViewDataSource"; this.Controls.Add(SitesTree); } protected override void Render(HtmlTextWriter writer) { RenderChildren(writer); } } }

Si desplegamos el WebPart veremos el resultado:
14092007_02

 

¡Curioso!