SharePoint Blog - René Hézser

Anmelden  RSS Feed RSS Feed
Startet die Suche

Archive

Kategorien

Links

Andere Blogs




ITaCS GmbH


Using the SharePoint SiteMapProvider  

Feb 012008

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...

 
Posted by René Hézser | 0  Comments | Trackback Url  | 0  Links to this post | Bookmark this post with:        
Tags: Development, SharePoint
Technorati Tags: ,

Links to this post

Comments

Name *:
URL:
Email:
Kommentar:


CAPTCHA Image Validation