SiteMapPath Control

The article explains how to use SiteMapPath Control. The SiteMapPath control is used for displaying paths of pages dynamically from the SiteMap file using the SiteMapDataSource control.

Add below code in the master page.

Aspx Code

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="true" />
            <asp:SiteMapPath ID="SiteMapPath1" runat="server" PathSeparator=" > " RenderCurrentNodeAsLink="false">
            </asp:SiteMapPath>
            <hr />
            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            </asp:ContentPlaceHolder>
        </div>
    </form>
</body>
</html>

Add a new site map page and add the site map nodes with reference url as shown below.

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" > 
    <siteMapNode url="~/Home.aspx" title="Home" description="Home Page" >
      <siteMapNode url="~/Products.aspx" title="Products" description="Products">
        <siteMapNode url ="~/Exporting.aspx" title="Exporting" description="Exporting Product Page"></siteMapNode>
        <siteMapNode url ="~/Importing.aspx" title="Importing" description="Importing Product Page"></siteMapNode>
      </siteMapNode>
      <siteMapNode url="~/About Us.aspx" title="About Us" description="About Us Page" />
      <siteMapNode url="~/ContactUs.aspx" title="Contact Us" description="Contact Us Page" />
    </siteMapNode>
</siteMap>

Output of SiteMapPath control

 

Demo Code

Download Demo