Using a Custom Data Source for Navigation

Through the Microsoft.SharePoint.WebControls.DelegateControl class, you can specify a custom data source control to provide nodes for Quick Launch navigation. The control that you specify through your delegate control candidate determines which provider to use as the data source for Quick Launch, which can be located in a database or in code. This type of customization changes the nodes that are displayed without modifying the way links are displayed.

You can replace the default nodes used in Quick Launch by specifying an alternate data source through a delegate control Feature. For information about delegate controls, see Delegate Control (Control Templatization).

The following example shows the default data source declaration in default.master, which specifies QuickLaunchDataSource as the ControlId value.

<SharePoint:DelegateControl runat="server"
  ControlId="QuickLaunchDataSource"
  Scope="Web">
  <asp:SiteMapDataSource
    SiteMapProvider="SPQuickLaunchProvider"
    ShowStartingNode="False"
    id="QuickLaunchSiteMap"
    runat="server"
  />
</SharePoint:DelegateControl>

You can create a Feature that overrides the default delegate control by adding a folder to the \TEMPLATE\FEATURES directory that specifies an alternate data source.

First create a Feature.xml file that specifies the strong-named assembly and class to use as the data source, and that references another XML file (in this example, called MyCustomNavigationSiteSettings.xml) that specifies the elements that form parts of the Feature.

<Feature  Id="541F5F57-C847-4e16-B59A-B31E90E6F9EA"
  Title="My Custom Left Navigation"
  Description="Enables custom navigation for the left navigation area."
  Version="12.0.0.0"
  Scope="Web"
  ReceiverAssembly="MyStrongAssemblyName, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
  ReceiverClass="MyNamespace.MyCustomNavigationHandler"
  xmlns="http://schemas.microsoft.com/sharepoint/">
  <ElementManifests>
    <ElementManifest Location="MyCustomNavigationSiteSettings.xml"/>
  </ElementManifests>
</Feature>

The following MyCustomNavigationSiteSettings.xml file redefines the site map provider to use as the QuickLaunchDataSource control, setting 50 as the Sequence attribute value, which specifies that the custom control be used instead for left navigation nodes.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Control Id="QuickLaunchDataSource" Sequence="50" 
    ControlClass="System.Web.UI.WebControls.SiteMapDataSource" 
    ControlAssembly="System.Web, version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
    <Property Name="SiteMapProvider">AreasAndPagesSiteMapProvider</Property>
    <Property Name="EnableViewState">true</Property>
    <Property Name="StartFromCurrentNode">true</Property>
    <Property Name="StartingNodeOffset">0</Property>
    <Property Name="ShowStartingNode">false</Property>
    <Property Name="ID">qlSiteMap</Property>
  </Control>
  <HideCustomAction
    Id="QuickLaunch"
    HideActionId="QuickLaunch"
    GroupId="Customization"
    Location="Microsoft.SharePoint.SiteSettings" />
</Elements>

For more information about creating and implementing Features in Windows SharePoint Services, see Working with Features. See ASP.NET 2.0 QuickStart Tutorial for information about creating an assembly to serve as a custom data source provider.

See Also

Tags :


Community Content

Andrew Connell [MVP]
Microsoft.SharePoint.Publishing ??

It does not appear the Microsoft.SharePoint.Publishing is a component of WSS 3.0. Is this documentation correct?

AC: Correct... it is a component of MOSS.

Tags :

Jaco Karsten
Control NOT of type IHierarchicalDataSource

When I try to run this code I get an error message saying:

"The DataSourceID of 'QuickLaunchMenu' must be the ID of a control of type IHierarchicalDataSource. A control with ID 'QuickLaunchSiteMap' could not be found."

Stack Trace:

[HttpException (0x80004005): The DataSourceID of 'QuickLaunchMenu' must be the ID of a control of type IHierarchicalDataSource. A control with ID 'QuickLaunchSiteMap' could not be found.]
System.Web.UI.WebControls.HierarchicalDataBoundControl.GetDataSource() +1415249
System.Web.UI.WebControls.HierarchicalDataBoundControl.ConnectToHierarchicalDataSource() +158
System.Web.UI.WebControls.HierarchicalDataBoundControl.OnLoad(EventArgs e) +16
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

What am I missing?

Tags :

Thomas Lee
Error in the example

There is an error in the code. The Control markup should look like this -

<Control Id="QuickLaunchDataSource" Sequence="50"
ControlClass="System.Web.UI.WebControls.SiteMapDataSource"
ControlAssembly="System.Web, version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Property Name="SiteMapProvider">AreasAndPagesSiteMapProvider</Property>
<Property Name="EnableViewState">true</Property>
<Property Name="StartFromCurrentNode">true</Property>
<Property Name="StartingNodeOffset">0</Property>
<Property Name="ShowStartingNode">false</Property>
<Property Name="ID">QuickLaunchSiteMap</Property>
</Control>

Tags : docbug

MUstafa Fazlyi
Create an assembly to server as a custom data source provider?

Does anyone have a "how to" link for creating the custom data source provider in an assembly? I am not able to find this info. from the ASP.NET Quickstart tutorial link given above.

Or a workaround for the error message: The SiteMapProvider 'AreasAndPagesSiteMapProvider' cannot be found.

Thanks.

Tags :

czullu
System.Web Version Ref. - Version not found & Question on behavior

I could not find the Version 2.0.3600.0 of System.Web even i have all the Frameworks on it. I have choosen the System.Web Version 2.0.0.0 instead. The problem i deal with extends to the sample, but i still like to ask.

I have two strange behaviors:

1. My Class Constructor derived from SPNavigationProvider gets call but the override method of GetChildNodes is never been called. I figured out that the Property currentNode is called an when i return a Custom node the GetChildNode is called after that - but then i loose the Menue-Entries from the underlying Provider. Is there something i'm missing?

2. If i'm in the Subsite and i click Fast after the refresh the Tab in the Top-Nav-Bar again, then sometimes i get the original Provider instead of mine - cloud that be caused by the Feature Stapling?

Thanks for Any Help.

Tags : contentbug

Charlie Holland
A step-by-step walkthough

I've prepared a walkthough that covers how to do this in a bit more detail, I've used the XmlDataSource as an example, so if you're looking for details on how to implement a custom provider this probably isn't the article for you, it only covers how to hook a custom provider into SharePoint.

http://www.chaholl.com/archive/2009/10/21/customising-navigation-data-sources.aspx


Tags :

Page view tracker