SharePoint 2013 Steps to Create Top Navigation using XMLDataSource

SharePoint 2013 Steps to Create Top Navigation using XMLDataSource
InfoPath alternatives for form designing SharePoint

In this post we will discuss how we can create a top navigation menu by using xml data source in SharePoint 2013. Here the menus will appear from a xml file.

Also read:
– How to extract dll from assembly folder and Install Uninstall DLL into Global Assembly Cache?

– Creating a SharePoint-Hosted Hello World App

– SharePoint 2013 Hide Ribbon from Anonymous users

For this particular example, I have created a custom master page by simply copy the existing Seattle master page.

The xml file which I have used here is like below structure.

<?xml version=”1.0″ encoding=”utf-8″ ?>
<menu text=”Home” url=”/sites/EnjoySharePoint/SitePages/Home.aspx”>
<menu text=”Menu-1″ url=”/EnjoySharePoint/page1.aspx”>
<submenu text=”Sub Menu-1″ url=”/EnjoySharePoint/page2.aspx”>
</submenu>
<submenu text=”Sub Menu-2″ url=”/EnjoySharePoint/pag3.aspx”>
</submenu>
</menu>
<menu text=”Menu-2″ url=”javascript:void(0);”>
<submenu text=”Sub Menu-2″ url=”javascript:void(0);”>
<submenu text=”Sub Sub Menu-2″ url=”/EnjoySharePoint/pag4.aspx”>
</submenu>
</submenu>
</menu>
</menu>

The file I have stored in the root by putting it using SharePoint designer.

Now Open your custom master page and search for below line:
<asp:ContentPlaceHolder id=”PlaceHolderTopNavBar” runat=”server”>

You will find the tag like below:

<asp:ContentPlaceHolder id=”PlaceHolderTopNavBar” runat=”server”>
<SharePoint:AspMenu
ID=”TopNavigationMenu”
Runat=”server”
EnableViewState=”false”
DataSourceID=”topSiteMap”
AccessKey=”<%$Resources:wss,navigation_accesskey%>”
UseSimpleRendering=”true”
UseSeparateCss=”false”
Orientation=”Horizontal”
StaticDisplayLevels=”2″
AdjustForShowStartingNode=”true”
MaximumDynamicDisplayLevels=”2″
SkipLinkText=”” />
</asp:ContentPlaceHolder>

Replace the below tag with the above tag.

<asp:ContentPlaceHolder id=”PlaceHolderTopNavBar” runat=”server”>
<SharePoint:AspMenu
ID=”TopNavigationMenu”
Runat=”server”
EnableViewState=”false”
DataSourceID=”xmlTopNavDataSource1″
AccessKey=”<%$Resources:wss,navigation_accesskey%>”
UseSimpleRendering=”true”
UseSeparateCss=”false”
Orientation=”Horizontal”
StaticDisplayLevels=”2″
AdjustForShowStartingNode=”true”
MaximumDynamicDisplayLevels=”4″
SkipLinkText=””
StaticSubMenuIndent=”0″
CssClass=”ms-topNavContainer”>
<DataBindings>
<asp:MenuItemBinding DataMember=”Menu” TextField=”text” ValueField=”text”
NavigateUrlField=”url” />
<asp:MenuItemBinding DataMember=”SubMenu” NavigateUrlField=”url” TextField=”text”
ValueField=”text” />
</DataBindings>
</SharePoint:AspMenu>
<asp:XmlDataSource
ID=”xmlTopNavDataSource1″
EnableCaching=”false”
DataFile=”/sites/EnjoySharePoint/TopNavMenu.xml”
runat=”server”
/>
</asp:ContentPlaceHolder>

Then Save and Publish the master page. Then set the master page and once you refresh page you will be able to see menu like below:

SharePoint 2013 Steps to Create Top Navigation using XMLDataSource
SharePoint 2013 Steps to Create Top Navigation using XMLDataSource

If you have not declare XmlDataSource as Safe, then you may face Safe control error.

Make sure to declare Safe as True like below in web.config file.

<SafeControl Assembly=”System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” Namespace=”System.Web.UI.WebControls” TypeName=”XmlDataSource” Safe=”True” AllowRemoteDesigner=”True” SafeAgainstScript=”False” />

Hope this will be helpful.

Similar SharePoint 2013 Tutorials

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →

Leave a Reply