Blue Theme Orange Theme Green Theme Red Theme
 
Ads by Lake Quincy Media
Home | Forums | Videos | Photos | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Login Close
User Id:
Password:
 
Forgot Password
Forgot Username
Why Register
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
 Resources  
Close
 Our Network  
Close
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:
Total page views :  11104
Total downloads :  311
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
SiteMap.zip
 
Become a Sponsor


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.

 


Login to add your contents and source code to this article
 About the author
 
Raj Kumar
Rajkumar is working as a senior software engineer has over 5 years experience working on ASP.NET, VB.NET, C#, AJAX and other latest technologies. He holds Master's degree in Computer Science. currently enjoying working on WPF, WCF, Silverlight, MVC, XAML.I can be reached on at raj2511984 at yahoo.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.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010 Professional
Microsoft Visual Studio 2010 Professional will launch on April 12, but you can beat the rush and secure your copy today by pre-ordering at the affordable estimated retail price of $549 (US). Pre-order now.
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.
Developer-Ready ASP.NET 2.0 Web Hosting with 3 MONTHS FREE
Now supporting .NET 3.0 Framework with Windows Workflow Foundation, Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), windows CardSpace (WCS)! Providing more flexibility for Developers with Web Services Support and a User/Permission Manger. Also supporting MS SQL 2005/2000 with Real-Time Backups, FREE Automated Attach .MDF Tool, FREE SQL Restore and Shrink SQL DB Tools, and SQL
 
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
SiteMap.zip
 
 Post a Feedback, Comment, or Question about this article
Subject:  
Comment:  
Become a Sponsor
 Comments

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2009.6.2
 © 2010  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.