Jaa


How to Create custom XMLSiteMapProvider and render it in SharePoint 2007 MOSS

All the OOB SiteMapProvider in MOSS are rendered through the delegate control through the control assembly. The OOB SiteMapProvider which are used in various site ranges in the MOSS are as follows : All the providers are self explanatory from their type name and their control class which renders is given beside :

 

Microsoft.SharePoint.Navigation.SPNavigationProvider

Microsoft.SharePoint.Navigation.SPSiteMapProvider

Microsoft.SharePoint.Navigation.SPContentMapProvider

Microsoft.Office.Server.Web.AdministrationQuickLaunchProvider

Microsoft.Office.Server.Web.SharedServicesQuickLaunchProvider

Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider (Note : The PortalSiteMapProvider can be rendered in 3 different navigation type : Global,Combined and current)

Microsoft.SharePoint.Portal.WebControls.SiteDirectoryCategoryProvider

Microsoft.SharePoint.Portal.MySiteMapProvider

Microsoft.SharePoint.Portal.MySiteLeftNavProvider

Microsoft.SharePoint.Portal.Analytics.UsagePagesSiteMapProvider

These providers have been registered through different features as a delegate control and the datasource can be used through a delegate control “ID” while rendering the provider. These providers are registered in the web.config as well in the following manner.

<siteMap defaultProvider="CurrentNavSiteMapProvider" enabled="true">

      <providers>

        <add name="SPNavigationProvider" type="Microsoft.SharePoint.Navigation.SPNavigationProvider, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />

        <add name="SPSiteMapProvider" type="Microsoft.SharePoint.Navigation.SPSiteMapProvider, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />

        <add name="SPContentMapProvider" type="Microsoft.SharePoint.Navigation.SPContentMapProvider, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />

        <add name="SPXmlContentMapProvider" siteMapFile="_app_bin/layouts.sitemap" type="Microsoft.SharePoint.Navigation.SPXmlContentMapProvider, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />

        <add name="AdministrationQuickLaunchProvider" description="QuickLaunch navigation provider for the central administration site" type="Microsoft.Office.Server.Web.AdministrationQuickLaunchProvider, Microsoft.Office.Server.UI, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />

        <add name="SharedServicesQuickLaunchProvider" description="QuickLaunch navigation provider for shared services administration sites" type="Microsoft.Office.Server.Web.SharedServicesQuickLaunchProvider, Microsoft.Office.Server.UI, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />

        <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" />

        <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 name="UsagePagesSiteMapProvider" description="Provider for navigation in Portal Usage pages" type="Microsoft.SharePoint.Portal.Analytics.UsagePagesSiteMapProvider, Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />

      </providers>

    </siteMap>

If you want to customize any of these providers to include or exclude any sitemap then you create a custom class inheriting the SiteMapProvider which you want to customize and can register it as a delegate control through feature. Of course need to make an entry for the custom provider in the web.config as well. Then you can use the custom provider to render your sitemap navigation.

In the above shown provider entries in the web.config if you notice the highlighted part then you can find the SPXMLContentMapProvider which provides the sitemap for the layouts pages in the form “SiteMap” file.

Based on this you can create your custom “SiteMap” file with your ASP.NET knowledge to render your custom sitemaps in the SharePoint. This blog post will walk you through the implementation of the custom SPXMLContentMapProvider for your custom Sitemap file.

Step 1: Create a feature to register your custom sitemap provider as a delegate control

The following code snippet shows the contents of “Elements.xml” file to register your custom site map provider as a delegate control :-

<Elements xmlns="https://schemas.microsoft.com/sharepoint/">

  <Control

    Id="CustomTopNavigationDataSource"

    Sequence="25"

    ControlClass="System.Web.UI.WebControls.SiteMapDataSource"

    ControlAssembly="System.Web, version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">

     

//Create the properties for the ID and the name of the sitemapprovider. The ID and the name will be used to identify the sitemapprovider to render in the pages and to read the entries from the web.config.

     

    <Property Name="ID">CustomtopSiteMap</Property>

    <Property Name="SiteMapProvider">CommonLawSiteMapProvider</Property>

    <Property Name="ShowStartingNode">true</Property>

  </Control>

</Elements>

Step 2: Create your custom sitemap file, consider it is custom.sitemap and place it under the Layouts/1033

Step 3: Make the site map provider entry in the web.config as follows :

<add name="CommonLawSiteMapProvider" siteMapFile="_layouts/1033/custom.sitemap" type="Microsoft.SharePoint.Navigation.SPXmlContentMapProvider, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />

 

Just install and activate the feature which register your custom sitemap provider as a delegate control. Then use this delegate control “ID” and the name of the provider to render the sitemap provider in the master pages.

One very important thing you can notice here is the path of the OOB sitemap file and the path of the custom sitemap file. The OOB sitemap file is in the “_app_bin” folder and the custom sitemap file is under the “_layouts/1033” folder.

The reason is that the OOB “layouts.sitemap” file is used to render the sitemap for the layouts pages which can be accessed only by the certain privileged users and not by the least privileged users like Visitors or viewers. So keeping this file in the “_app_bin” folder doesn’t do any harm. But consider your custom sitemap file is used to provide the sitemap for all the pages in the site then regular visitor users with least privilege will not be able to find the file and will be getting the error message stating that the file required by the “XMLSiteMapProvider” doesn’t exist if the sitemap file is in the “_app_bin” folder. The admin users will not be encountering with this issue and the sitemap will be rendered fine but the least privilege users will be encountering this issue as they don’t have permission in the “_app_bin” folder. So either you can give permission to everyone in the “_app_bin” folder else you can keep your custom sitemap file in the “_layouts/1033” folder.

Hope the second option on keeping the sitemap file under the “_layouts/1033” makes more sense than keeping the sitemap file in the “_app_bin” folder and giving the permission to everyone.

Comments