Click here to Skip to main content
1,837 members
Articles / Security / ASP.NET
Article

How to: Use TreeView in Current Navigation in SharePoint

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
12 Apr 2012CPOL 7.3K  
This article shows how to use the ASP.NET TreeView control in SharePoint.

TreeView in SharePoint

Introduction

This article explains how to use the ASP.NET TreeView for the current navigation in SharePoint (WSS 3/MOSS 2007).

This is useful if you use SharePoint as a Content Management System, for example, if you have a publishing site with many pages sorted in a content hierarchy that you wish to present in a user-friendly treeview navigation control.

Naturally, you could benefit with combining the treeview control with a horizontal menu control on your master page so that the primary, global navigation is presented by a horizontal menu on the top of your page, and the secondary, local navigation is presented by a vertical tree on the left side of your site.

Background

Out-of-the box SharePoint uses the SharePoint:AspMenu for the current navigation, usually shown on the left side of a page.

SharePoint also shpis with a SharePoint:SPTreeView control that shows the categories of a site. However, if you want to render the current navigation in the left side as a tree, with expandable and collapsible menu items, you have to do a few changes to your master page and your webconfig.sps.xml file.

Using the Code

  1. If you have a content placeholder with the ID "PlaceHolderLeftNavBar", then locate the SharePoint:AspMenu within the placeholder and replace it with ASP:TreeView.
  2. If you do not have a placeholder, then insert the control on your master page.

  3. As the data source for the TreeView control, use SiteMapProvider="CurrentNavSiteMapProviderNoEncode".
  4. If you already have a "PlaceHolderLeftNavBar" content placeholder, then you can simply change the SiteMapProvider="CurrentNavSiteMapProvider" beneath the SharePoint:AspMenu replaced in step 1.

    Here, I use the PortalSiteMap data source:

    ASP.NET
    <ASP:TreeView id="MyID" runat="server" DataSourceID="MyDatasource"
        ExpandDepth="0"></ASP:TreeView>
     <PublishingNavigation:PortalSiteMapDataSource ID="MyDatasource"
        runat="server" SiteMapProvider="CurrentSiteMapProviderNoEncode"
  5. Finally, you need to change your webconfig.sps.xml files, which you should find here: "C:\\Progam Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG".
  6. Locate the provider named "CurrentNavSiteMapProviderNoEncode" and add the attribute RequireUniqueKeysForNodes="true".

    The following shows the relevant section:

    XML
    <add path="configuration/system.web/siteMap/providers"
        id="{009E5494-26C5-4181-936F-4D16F444B642}">
    <add name="GlobalNavSiteMapProvider"
        description="CMS provider for Global navigation"
        type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider,
        Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral,
        PublicKeyToken=71e9bce111e9429c" NavigationType="Global" EncodeOutput="true"/>
    <add name="CombinedNavSiteMapProvider"
        description="CMS provider for Combined navigation"
        type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider,
        Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral,
        PublicKeyToken=71e9bce111e9429c" NavigationType="Combined" EncodeOutput="true"/>
    <add name="CurrentNavSiteMapProvider"
        description="CMS provider for Current navigation"
        type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider,
        Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral,
        PublicKeyToken=71e9bce111e9429c" NavigationType="Current" EncodeOutput="true"/>
    <add name="CurrentNavSiteMapProviderNoEncode"
        description="CMS provider for Current navigation, no encoding of output"
        type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider,
        Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral,
        PublicKeyToken=71e9bce111e9429c" NavigationType="Current" EncodeOutput="false"
        RequireUniqueKeysForNodes="true"/>
    <add name="SiteDirectoryCategoryProvider"
        description="Site Directory category provider"
        type="Microsoft.SharePoint.Portal.WebControls.SiteDirectoryCategoryProvider,
        Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral,
        PublicKeyToken=71e9bce111e9429c"/>
    <add name="MySiteMapProvider"
        description=
        "MySite provider that returns areas and based on the current user context"
        type="Microsoft.SharePoint.Portal.MySiteMapProvider,
        Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral,
        PublicKeyToken=71e9bce111e9429c"/>
    <add name="MySiteLeftNavProvider"
        description=
           "MySite Left Nav provider that returns areas 
            and based on the current user context"
           type="Microsoft.SharePoint.Portal.MySiteLeftNavProvider,
           Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral,
           PublicKeyToken=71e9bce111e9429c"/>
    </add>
  7. Save your files and reset IIS.

Points of Interest

There are various properties that you can use to customize the TreeView control.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Denmark Denmark
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --