C#: Working with the SiteMapPath Control

Category: ASP.NET

C#: SiteMapPath Control

By: Zack Turnbow

Introduction

Most business web sites can have a large footprint, that is, several pages to visit. It can be difficult to navigate through the site with just normal menus. Many companies started creating “bread crumb” trails so that a user will know exactly where they are in the web site. This becomes increasingly difficult when a site keeps adding pages as it evolves. ASP.NET 2.0 solved this issue by introducing the SiteMapPath control.

If you're ever in the market for some great Windows web hosting, try Server Intellect. We have been very pleased with their services and most importantly, technical support.

Implementation

Start fresh with a new web application in Visual Studio. The SiteMapPath control is used in conjunction with a Web.sitemap file. So the first action required is to add a Web.sitemap item to the project.

1
[Click to see full-size]

Before adding anything to the new file, a little explanation and planning needs to take place. The Web.sitemap file is just an XML file that holds the structure of the web site. So it is a good idea to take some time to plan the initial layout of the web site. Below is a basic structure of a typical web site:

Home
About Us
Mission Statement
Company History
Press Releases
Products
Product 1
Product 2
Services and Parts
Parts for Sale
Repair Service
Technical Assistance
Documentation
Forum
Support
Sales
New Customer
Existing Customer
Customer Feedback

We are using Server Intellect and have found that by far, they are the most friendly, responsive, and knowledgeable support team we've ever dealt with!

As shown, the site layout might cause a user (customer) to get lost in the site. So with this lay out in mind, enter the following code into the Web.sitemap file.

<?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">
<siteMapNode url="AboutUs.aspx" title="About Us" description="About Us">
<siteMapNode url="Mission.aspx" title="Mission Statement" description="Our Mission Statement" />
<siteMapNode url="History.aspx" title="Company History" description="Our Company History" />
<siteMapNode url="Press.aspx" title="Press Releases" description="Press Releases" />
</siteMapNode>
<siteMapNode url="Products.aspx" title="Products" description="Company Products">
<siteMapNode url="Product1.aspx" title="Product 1" description="Prodcut 1 Information" />
<siteMapNode url="Product2.aspx" title="Product 2" description="Prodcut 2 Information" />
</siteMapNode>
<siteMapNode url="Services.aspx" title="Services and Parts" description="Services and Parts">
<siteMapNode url="Parts.aspx" title="Parts for Sale" description="Parts for Sale" />
<siteMapNode url="Repair.aspx" title="Repair Service" description="Repair Service" />
<siteMapNode url="Technical.aspx" title="Technical Assistance" description="Technical Assistance">
<siteMapNode url="Documentation.aspx" title="Documentation" description="Documentation" />
<siteMapNode url="Forum.aspx" title="Forum" description="Forum" />
<siteMapNode url="Support.aspx" title="Product Support" description="Product Support" />
</siteMapNode>
<siteMapNode url="Sales.aspx" title="Sales" description="Sales">
<siteMapNode url="NewCustomer.aspx" title="New Customer Sales" description="New Customer Sales" />
<siteMapNode url="Customer.aspx" title="Existing Customer Sales" description="Existing Customer Sales" />
<siteMapNode url="Feedback.aspx" title="Customer Feedback" description="Customer Feedback" />
</siteMapNode>
</siteMapNode>
</siteMapNode>
</siteMap>


Each level of the layout above corresponds to an outer node of the Web.sitemap file. For instance, the About Us node is

<siteMapNode url="AboutUs.aspx" title="About Us" description="About Us">
.
.
.
</siteMapNode>

with the mission statement, history, and press releases nodes being inside the About Us node. This XML file will give an easier way of tracking site navigation and the ability to add, change, or delete pages. Now that the sitemap has been defined, the next step is to create the master page to be the template for each page.

Yes, it is possible to find a good web host. Sometimes it takes a while. After trying several, we went with Server Intellect and have been very happy. They are the most professional, customer service friendly and technically knowledgeable host we've found so far.

2
[Click to see full-size]

On the master page, add a SiteMapPath control and a Menu control to the page. Now it is time to create each of the pages listed in the Web.sitemap file. For this article, only the Home, the AboutUs, the Mission, the History, and the Press aspx pages will be created. Make sure to set the master page to the once created above when adding the pages to the project.

3

Go back to the master page and format the Menu control to have the layout displayed below.

4
[Click to see full-size]

Go to the Home page and a Label on the work area and give the label the name of Home.

5
[Click to see full-size]

****************************

Repeat the steps for the AboutUs, the Mission, the History, and the Press aspx pages. Once this is complete, run the application and navigate the pages using the SiteMapPath control.

6
[Click to see full-size]

 

7
[Click to see full-size]

This article has shown another option for a user to navigate a web site as well an easy way for the developer to keep track of site navigation.

We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.

 

 

What have we learned?

How to create a Web.sitemap file to be used in site navigation.
How to create a master page so that all other pages use it as a template.
How to incorporate the SiteMapPath control along with a Menu control to assist in site navigation.

Attachments



Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!

Leave a Comment

Comments on this Article

Post a Comment
Name:
Website:
Email:
Comments:

#1 vijayvardhan`

Posted By: vijayvardhan` | 12.01.2008 at 10:16 AM

it is verygood for the developers.

#2 Amandeep Singh

Posted By: Amandeep Singh | 1.03.2009 at 12:19 AM

thnx your posted help was very good, i got a very good help through it

with regards

aman

#3 Yogesh S

Posted By: Yogesh S | 4.30.2009 at 4:01 AM

It is good but needs more explanation

#4 online games

Posted By: online games | 11.24.2009 at 11:00 PM

it is verygood for the developers.

#5 vivek

Posted By: vivek | 1.07.2010 at 5:30 AM

No any email in my id

#6 vivek

Posted By: vivek | 1.07.2010 at 5:30 AM

Thanks for this code

#7 rizwan

Posted By: rizwan | 1.19.2010 at 9:47 AM

thanks you have solved my problem

great stuff

#8 Gun Safes Sale

Posted By: Gun Safes Sale | 1.26.2010 at 5:13 PM

thnx your posted help was very good, i got a very good help through i

#9 actual exam

Posted By: actual exam | 2.01.2010 at 7:44 AM

Some of the facts regarding sitemath is as follow:

The SiteMapPath control displays a list of links representing the user's current page and the hierarchal path back to the root of the website. This functionality is sometimes referred to as a breadcrumb for the user

The SiteMapPath control relies on a SiteMapProvider to retrieve the data that it will display. Unlike the Menu or Treeview control the SiteMapPath control does NOT use a SiteMapDataSource control and can not be bound to other hierarchal datasource controls.

The default SiteMap provider will automatically be used by the control or you can set the SiteMapProvider property on the control to point to any provider already configured in the web.config file.

#10 portable clothes rack

Posted By: portable clothes rack | 2.04.2010 at 2:41 AM

The SiteMapPath control relies on a SiteMapProvider to retrieve the data that it will display. Unlike the Menu or Treeview control the SiteMapPath control does NOT use a SiteMapDataSource control and can not be bound to other hierarchal datasource controls.

#11 640-802

Posted By: 640-802 | 2.12.2010 at 12:33 AM

Laying out the analytic anatomy of a Web appliance provides a starting point for architecture user interface aeronautics controls. ASP.NET 2.0 simplifies the architecture of such controls with the Website Map Web server ascendancy and accompanying aeronautics controls. The website anatomy is abundant in a website map book and acclimated to abide aeronautics elements. In antecedent versions of ASP.NET, this simple action captivated a block of development time.

#12 350-001

Posted By: 350-001 | 2.12.2010 at 12:34 AM

The website map is the abject for application the aeronautics controls accessible in ASP.NET 2.0. The website map is acclimated as the abstracts antecedent for the aeronautics controls. These aeronautics controls cover Menu, SiteMapPath, and TreeView. Next week, I will accommodate the data of application the SiteMapPath ascendancy with a website map.

#13 VCP-310

Posted By: VCP-310 | 2.12.2010 at 12:35 AM

The System.Web namespace contains the SiteMap class, which corresponds to the ASP.NET website map feature. It is an in-memory representation of the aeronautics anatomy for a site. The chic provides admission to the assorted elements aural a website map. The two a lot of important (or used) backdrop of the chic are CurrentNode and RootNote.

#14 free game

Posted By: free game | 3.07.2010 at 3:30 AM

Hi webmaster, your website's theme is amazing and i like it. Your posts are totally great. Please keep up the good work. Greets!!

#15 cool games

Posted By: cool games | 3.07.2010 at 3:30 AM

Hello, your web page's theme is nice and i like it. Your blog posts are cool. Please keep them coming. Greets..

#16 1Z0-053 question

Posted By: 1Z0-053 question | 3.19.2010 at 5:41 AM

For all I know this could be a really old entry, since there are no date marker on the article. In that case I apologize.

#17 Swimming Pools

Posted By: Swimming Pools | 3.20.2010 at 6:10 AM

I have been working with this software from last 2 to 3 years. And I really found this very easy to use and it always have helped me in almost every theme.

#18 funny t shirt

Posted By: funny t shirt | 4.04.2010 at 10:46 PM

thank you so much for this incredibly astounding column.

#19 Animal jewelry

Posted By: Animal jewelry | 4.08.2010 at 8:57 AM

Another great post admin. This is such good info for my research. I will bookmark your post here on Digg.

#20 testking 000-210

Posted By: testking 000-210 | 5.06.2010 at 2:39 AM

I like your blog very much.

#21 testking 70-272

Posted By: testking 70-272 | 5.06.2010 at 2:39 AM

Thanks for sharing.

#22 testking 70-290

Posted By: testking 70-290 | 5.06.2010 at 2:39 AM

Your blog is great. I love it.

#23 testking HP0-S21

Posted By: testking HP0-S21 | 5.10.2010 at 1:08 AM

I like your blog very much.

#24 testking 000-025

Posted By: testking 000-025 | 5.10.2010 at 1:09 AM

Thanks for sharing.

#25 testking 000-200

Posted By: testking 000-200 | 5.10.2010 at 1:09 AM

Good posting thanks.

#26 coach handbags

Posted By: coach handbags | 5.24.2010 at 3:18 AM

The Far East aristocrat becomes fashion new influence … “the Russian always to choose best goods - - Chanel in the best brand the handbag and the coat,

#27 wholesale shoes

Posted By: wholesale shoes | 5.24.2010 at 3:33 AM

Spring summer pocket perfect supporting role (figure) except heart shape brooch, earring, necklace,

#28 vibram five fingers

Posted By: vibram five fingers | 6.05.2010 at 9:25 AM

That great!Great article!useful That what i'm looking for!

#29 nike air max

Posted By: nike air max | 6.05.2010 at 9:28 AM

This article give me a great help!thank you very much!

#30 michael jordan shoes

Posted By: michael jordan shoes | 6.18.2010 at 8:58 PM

good post!!thank you

#31 Sam

Posted By: Sam | 7.09.2010 at 8:22 AM

Okey

#32 tiffany co

Posted By: tiffany co | 7.21.2010 at 3:06 AM

For classic and quality genuine silver jewelry, many people choose Tiffany & Co brand.Now,we present you the hottest Tiffany silver jewelry .get more http://www.tiffanyonsale.com/

#33 tiffany jewelry

Posted By: tiffany jewelry | 7.21.2010 at 3:06 AM

For classic and quality genuine silver jewelry, many people choose Tiffany & Co brand.Now,we present you the hottest Tiffany silver jewelry .get more http://www.tiffanyonsale.com/

#34 tiffany jewellery

Posted By: tiffany jewellery | 7.21.2010 at 3:06 AM

For classic and quality genuine silver jewelry, many people choose Tiffany & Co brand.Now,we present you the hottest Tiffany silver jewelry .get more http://www.tiffanyonsale.com/

#35 tiffany jewellery

Posted By: tiffany jewellery | 7.21.2010 at 3:06 AM

For classic and quality genuine silver jewelry, many people choose Tiffany & Co brand.Now,we present you the hottest Tiffany silver jewelry .get more http://www.tiffanyonsale.com/

#36 tiffany ring

Posted By: tiffany ring | 7.26.2010 at 7:04 AM

This is exactly cheap tiffany jewelry you can get cheap Tiffany Rings, Necklaces, Errings, Bracelets and other Tiffany Jewellery.get more http://www.tiffanyonsale.com/

#37 tiffany bracelet

Posted By: tiffany bracelet | 7.26.2010 at 7:05 AM

This is exactly cheap tiffany jewelry you can get cheap Tiffany Rings, Necklaces, Errings, Bracelets and other Tiffany Jewellery.get more http://www.tiffanyonsale.com/

#38 tiffany necklace

Posted By: tiffany necklace | 7.26.2010 at 7:05 AM

This is exactly cheap tiffany jewelry you can get cheap Tiffany Rings, Necklaces, Errings, Bracelets and other Tiffany Jewellery.get more http://www.tiffanyonsale.com/

#39 nike shoes on sale

Posted By: nike shoes on sale | 8.02.2010 at 3:53 AM

www.cheapshoeshop.com/.../Air-Max-1.html

#40 andy

Posted By: andy | 8.03.2010 at 4:13 AM

<a href="http://www.shinyawl.com">cartier jewelry</a> for the birthday gift? <a href="http://www.linksvip.uk.com">links of london jewellery</a> Is the better way to service ur purpose I think. I don’t recommended <a href="http://www.shinyawl.com">cartier jewelry</a> for the reason that the 2nd jewellery is more famous than it. Or what about <a href="http://www.yofollow.com">nfl jerseys</a>? I mean u can do it for her bro~uh..just a joke, I think follow the <a href="http://www.mbtag.com">mbt shoes</a> tips can work out the whole thing. So, see u next time, wishes that I can see ur <a href="http://www.linksvip.uk.com">links of london jewellery</a> next time! Cy!

#41 andy

Posted By: andy | 8.03.2010 at 4:13 AM

jhyhgjmnhjmhj

#42 mbt shoes

Posted By: mbt shoes | 8.10.2010 at 11:57 PM

it's nice /thanks very much.

#43 replica jewelry

Posted By: replica jewelry | 8.23.2010 at 10:58 PM

<a href="http://www.jewelry-tiffany.com">jewelry tiffany</a> mother fell in love with <a href="http://www.imitation-watches.com/replica-watches-ROLEX-226-b0.html">rolex imitation</a>