Did you ever wanted to create a Webpart for site navigation? Well, you can use the SPSiteMapProvider from SharePoint.
In your Webpart you could use this code to access the SPSiteMapProvider.
1: SPSiteMapProvider sitemapProvider = (SPSiteMapProvider)SiteMap.Providers["SPSiteMapProvider"];
2: SiteMapDataSource datasource = new SiteMapDataSource();
3: datasource.Provider = sitemapProvider;
This Datasource can be the datasource for a regular ASP.NET Treeview Control:
1: TreeView treeview = new TreeView();
2: treeview.NodeIndent = 10;
3: treeview.DataSource = datasource;
4: treeview.TreeNodeDataBound += _TV_TreeNodeDataBound;
5: treeview.DataBind();
In the DataBound Event we will make sure, that nodes within the current navigation path are expanded, and others are collapsed:
1: void _TV_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
2: { 3: SiteMapNode node = (SiteMapNode) e.Node.DataItem;
4: if (_CurrentUrl.StartsWith(node.Url))
5: e.Node.Expand();
6: else
7: e.Node.Collapse();
8:
9: if (_CurrentUrl == node.Url)
10: e.Node.Select();
11: }
If you like, you can set the styles for the selected node...