Tuesday, January 24, 2012

Custom Site map provider


SharePoint provides global navigation display multiple level of navigation with some limitations

Scenario:
clip_image001
In the above screen Corporate is sub site. And IT, HR, Admin and Corporate Matter are the document libraries. We need one more level of menu with folders of each library.
We can’t achieve this scenario by increasing the StaticDisplayLevels to 2 in the Global navigation menu in the master page.
We take custom site map provider approach to achieve the functionality
1. Create notepad file and name it as CustomSiteMap.sitemap
2. Open the document create nodes like :
<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
<siteMapNode title="" url="">
<siteMapNode title="Corporate" url="/Pages/Corporate.aspx">
<siteMapNode title="IT" url="/Lists/IT/AllItems.aspx">
<siteMapNode title="Hydra" url="/Lists/HR/AllItems.aspx"/>
</siteMapNode>
<siteMapNode title="HR" url="/Lists/HR/AllItems.aspx"/>
<siteMapNode title="Admin" url="/Lists/admin/AllItems.aspx"/>
<siteMapNode title="Corporate Matters" url="/Lists/cormatter/AllItems.aspx"/>
</siteMapNode>
</siteMapNode>
</siteMap>

3. Save the file in 14hive/_Layouts/<CustomSiteProvider>/
4. Open targeted applications’ web.config file find for <providers> tag
5. Make this entry : <add name="CustomGlobalNavSiteMapProvider" siteMapFile="/_layouts/ CustomSiteProvider / CustomSiteMap.sitemap" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
6. Save and close the web.config
7. Open targeted application master page in SP designer
8. Try to simulate following snippet
<SharePoint:AspMenu
ID="TopNavigationMenuV4"
Runat="server"
EnableViewState="false"
DataSourceID="topSiteMap"
AccessKey="<%$Resources:wss,navigation_accesskey%>"
UseSimpleRendering="true"
UseSeparateCss="false"
Orientation="Horizontal"
StaticDisplayLevels="1"
MaximumDynamicDisplayLevels="3"
SkipLinkText=""
CssClass="s4-tn" Width="1024px">
</SharePoint:AspMenu>
<SharePoint:DelegateControl runat="server" ControlId="CustomXmlContentMapProvide" Id="topNavigationDelegate">
<Template_Controls>
<asp:SiteMapDataSource
ShowStartingNode="False"
SiteMapProvider="CustomGlobalNavSiteMapProvider"
id="topSiteMap"
runat="server"/>
</Template_Controls>
</SharePoint:DelegateControl>

9. Publish the master page.
10. Browse the application, and we can see custom global navigation

No comments:

Post a Comment