The SiteMapPath control basically is used to access web pages of the website from one webpage to another. It is a navigation control and displays the map of the site related to its web pages. This map includes the pages in the particular website and displays the name of those pages. You can click on that particular page in the Site Map to navigate to that page. We can say that the SiteMapPath control displays links for connecting to URLs of other pages. The SiteMapPath control uses a property called SiteMapProvider for accessing data from databases and it stores the information in a data source. The SiteMapProvider internally utilizes the SiteMapProvider abstract class defined under the System.Web namespace. The representation of the SiteMapPath control is as follows:

Root Node->Child Node

Public Properties of SiteMapPath class

ParentLevelsDisplayed : It specifies the number of levels of parent nodes and then displays the control accordingly related to the currently displayed node.

RenderCurrentNodeAsLink : It specifies whether or not the site navigation node that represents the currently displayed page is rendered as a hyperlink.

PathSeperator : It specifies the string that displays the SiteMapPath nodes in the rendered navigation path.

Style properties of the SiteMapPath class

CurrentNodeStyle : It specifies the style used for the display text for the current node.

RootNodeStyle : It specifies the style for the root node style text.

NodeStyle : It specifies the style used for the display text for all nodes in the site navigation path.Creating the SiteMapPath Control : Now lets create an application by using the SiteMapPath control. In this application we design the following three pages:

The Home Page (Default.aspx)

The First Page (myweb1.aspx)

The Second page (myweb2.aspx)

Now we can use the SiteMapPath control using following steps:

Step 1 : Open Microsoft Visual Studio 2010.

Step 2 : Select File->New->Web Site.

Step 3 : Select ASP.NET Web Site and name it as mywebsite.

Step 4 : Add two web forms to the application named myweb1.aspx and myweb2.aspx by performing the following steps:

Move to the Solution Explorer window

Right-click on the application name and select the Add New Item option from the context menu

Name the web form as myweb1.aspx and click the Add button

Step 5 : Similarly add the myweb2.aspx web form to the application. After that we have to add the Site Map file into the project. The Site Map file is the XML file and has the extension .sitemap. The steps are as follows.

Step 6 : Right-click the application in the Solution Explorer window and then click the Add New Item option from the context menu.

Step 7 : Select the SiteMap Template from the Templates Pane. Note that, by default, the file has the name web.sitemap.

Step 8 : Now click the Add button to add the sitemap file to our application.

Step 9 : Now we can check that the sitemap file has been included in our project and we can see it in the Solution Explorer. And now we have to set the URL and title attributes in the sitemap file.

Step 10 : Now Add one SiteMapPath control on the Default.aspx page from the navigation tab of the toolbox.

Step 11 : Add three labels and two hyperlink controls from the toolbox to the Default.aspx page and set the text property of the control.

Step 12 : Now set the NavigateUrl property of the first hyperlink control and select the myweb1.aspx file as follows.

Step 13 : Now set the NavigateUrl Property of second hyperlink control and select myweb2.aspx file.

The source code of the Default.aspx page is as follows:

<%@PageTitle="Home Page"Language="C#"MasterPageFile="~/Site.master"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"%><asp:ContentID="HeaderContent"runat="server"ContentPlaceHolderID="HeadContent"></asp:Content><asp:ContentID="BodyContent"runat="server"ContentPlaceHolderID="MainContent"><asp:LabelID="Label1"runat="server"Text="I have designed my website by using SiteMapPath control in ASP.NET"Font-Bold="True"Font-Names="Arial Black"Font-Size="Large"></asp:Label><br/><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:LabelID="Label2"runat="server"Text="sitemap:"></asp:Label> &nbsp;<asp:SiteMapPathID="SiteMapPath1"runat="server"></asp:SiteMapPath><br/><br/><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:LabelID="Label3"runat="server"Text="Click any link below to go to desired page............."></asp:Label><br/><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:HyperLinkID="HyperLink1"runat="server"NavigateUrl="~/myweb1.aspx">Click here to go to first page </asp:HyperLink> &nbsp;&nbsp;&nbsp;&nbsp;<asp:HyperLinkID="HyperLink2"runat="server"NavigateUrl="~/myweb2.aspx">click here to go to second page</asp:HyperLink></asp:Content>Step 14 : Now in the design mode of the myweb1.aspx page, add the same control but add only one hyperlink control and set its NavigateUrl property to myweb2.aspx then click ok.