Blue Theme Orange Theme Green Theme Red Theme
 
Team Foundation Server Hosting
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Discover the top 5 tips for understanding .NET Interop
Search :       Advanced Search »
Home » ASP.NET & Web Forms » Site Map in ASP.NET 3.5

Site Map in ASP.NET 3.5

This sample shows how to use a Site Map control in ASP.NET 3.5.

Author Rank :
Page Views : 35902
Downloads : 1174
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
SiteMap.zip
 
 
Nevron Chart
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


The SiteMap control available in ASP.NET 3.5 provides a site navigation view in a hirerchichal format. The data source for the SiteMap control is an XML file that has name and URL of the site navigation.

The starting point in site map based navigation is the site map provider. ASP.NET ships with a single site map provider, named XMLSiteMapProvider which is able retrieve site map information from as XML file. If you want to retrieve a site map from another location or in a custom format, you will need to create your own site map provider.

The XmlSiteMapProvider looks for a file named Web.sitemap in the root of the virtual directory. Like all site map providers , its task is to extract the site map data and create the corresponding SiteMap object. This SiteMap object is then made available to other control through the SiteMapDataSource.

Site maps are used in conjunction with the SiteMapDataSource, SiteMapPath, and other controls to render an effective navigation interface for users to navigate a Web site. A SiteMap object is a component of the ASP.NET site navigation infrastructure that provides access to read-only site map information for page and control developers using navigation and SiteMapDataSource controls. Other components of the ASP.NET site navigation infrastructure include the SiteMapProvider and XmlSiteMapProvider classes, the Web.sitemap file, and the various controls that work with the SiteMap class, such as the SiteMapPath control, to render content and menus.

The SiteMap has several functions:

·         It provides the root node of the site navigation hierarchy (there can be only one root node).

·         It identifies which site map provider is the principal, or default, provider.

·         It keeps track of all the provider objects that are used to create the SiteMap.

OK, let's get started. Create an ASP.NET application using Visual Studio 2008.

Now add a Site Map file to the project by right clicking on the project name, select Add New Item and select Site Map from the templates.

Image1.jpg 

Figure 1.

After adding a Site Map file, we need to add Site Map Nodes represeted by siteMapNode XML elements as shown below.

Here is my final Web2.sitemap looks like. The siteMapNode has a title and a url attribute that represent the title and URL of the link.

<?xml version="1.0" encoding="utf-8" ?>

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >

    <siteMapNode url="" title="Modeling Corner"  description="This is modeling site">

            <siteMapNode title="Header"  description="This is modeling corner header">

            <siteMapNode url="www.modelingcorner.com" title="Models"  description="This is model section">

                  <siteMapNode url="http://www.modelingcorner.com/Men/Default.aspx" title="Men Models"  description="This section is for men models" />

                  <siteMapNode url="http://www.modelingcorner.com/Women/Default.aspx" title="Women Models"  description="This section is for women models" />

                  <siteMapNode url="http://www.modelingcorner.com/Teens/Default.aspx" title="Teen Models"  description="This section is for teen models" />

                  <siteMapNode url="http://www.modelingcorner.com/Kids/Default.aspx" title="Kid Models"  description="This section is for kid models" />

                  <siteMapNode url="http://www.modelingcorner.com/Babies/Default.aspx" title="Baby Models"  description="This section is for baby models" />

            </siteMapNode>

            <siteMapNode url="http://www.modelingcorner.com/Photographer/AllPhotographers.aspx" title="Photographers"  description="This is photographer section"></siteMapNode>

            <siteMapNode url="http://www.modelingcorner.com/Agents/Default.aspx" title="Agencies"  description="This is agencies section"></siteMapNode>

            <siteMapNode url="http://www.modelingcorner.com/Blogs/AllBlogs.aspx" title="Blogs"  description="This is blogs section"></siteMapNode>

            <siteMapNode url="http://www.modelingcorner.com/News/ShowAllNews.aspx" title="News"  description="This is news section"></siteMapNode>

            <siteMapNode url="http://www.modelingcorner.com/CastingCalls/ViewAllCasting.aspx" title="Castings"  description="This is castings section"></siteMapNode>

            <siteMapNode url="http://www.modelingcorner.com/Video/AllVideo.aspx" title="Videos"  description="This is videos section"></siteMapNode>

            <siteMapNode url="http://www.modelingcorner.com/Forum/Default.aspx" title="Forums"  description="This is forum section"></siteMapNode>

    </siteMapNode>

            <siteMapNode title="Footer" url="" description="This is modeling corner footer">

                  <siteMapNode url="http://www.maximumasp.com/" title="Hosted By MaximumASP"  description="This is host website name"></siteMapNode>

                  <siteMapNode url="http://www.modelingcorner.com/" title="Home"  description="This is home page name"></siteMapNode>

                  <siteMapNode url="http://www.modelingcorner.com/Home/ContactUs.aspx" title="Contact Us"  description="This is contact us page"></siteMapNode>

                  <siteMapNode url="http://www.modelingcorner.com/Home/AboutUs.aspx" title="About Us"  description="This is about us page"></siteMapNode>

                  <siteMapNode url="http://www.modelingcorner.com/Home/Help.aspx" title="Help"  description="This is help page"></siteMapNode>

                  <siteMapNode url="http://www.modelingcorner.com/Home/SearchTypes.aspx" title="Search"  description="This is search page"></siteMapNode>

            </siteMapNode>

      </siteMapNode>

      <!-- -->

</siteMap>

 

Now let's add a SiteMapDataSource control to the ASP.NET page. This is my page page looks like.

<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />

        <asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1"

            BackColor="#F7F6F3" DynamicHorizontalOffset="2" Font-Names="Verdana"

            Font-Size="14px" ForeColor="#7C6F57" StaticSubMenuIndent="14px">

            <StaticSelectedStyle BackColor="#5D7B9D" />

            <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />

            <DynamicHoverStyle BackColor="#7C6F57" ForeColor="White" />

            <DynamicMenuStyle BackColor="#F7F6F3" />

            <DynamicSelectedStyle BackColor="#5D7B9D" />

            <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />

            <StaticHoverStyle BackColor="#7C6F57" ForeColor="White" />

        </asp:Menu>

 

Now if you run and look at the output, you will see output looks like following where you can click on the root node and it will display next level nodes and so on.

Image2.jpg

Download the attached source code for more details.

 

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Raj Kumar

Raj Kumar is a Microsoft MVP and Senior Software Engineer with lots of hands on experience using ASP.NET 2.0/3.5, AJAX, MVC, C#, Visual Basic .NET, SQL Server 2005/2008, Oracle, WPF, WCF, XAML and Silverlight. He has over 6 years of IT experience working most on Microsoft technologies. He holds Master's degree in Computer Science. When he is not writing code, he likes to write articles and play cricket.

Reach him at raj2511984@gmail.com 

 

Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the Top 5 .NET Memory Management Fundamentals
To write the best .NET code, you need to know exactly how the .NET framework really manages memory. Ricky Leeks presents the Top 5 fundamental facts of .NET memory management. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
DevExpress Free UI Controls
Become a Sponsor
 Comments
study by sanjay On March 18, 2010
i have study
Reply | Email | Modify 
HAI FRIEND by bhanusri On June 23, 2010
Superb ..nice Explanation Keep it up...
Reply | Email | Modify 
Re: HAI FRIEND by Raj On February 22, 2011
Thanks mate
Reply | Email | Modify 
Hi by Bikram On July 7, 2010
Nice Menu.....
Reply | Email | Modify 
Thanks by Sahil On February 20, 2011
Nice explaination...I understood everything...
Reply | Email | Modify 
Cool by Nsubuga On July 14, 2011
nice job dude!
Reply | Email | Modify 
Discover the top 5 tips for understanding .NET Interop
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.