Click here to Skip to main content
Click here to Skip to main content

Site Map Web Part (SharePoint Server 2010)

By , 19 May 2010
 
1.gif

Introduction

Site Map Web Part displays structure of a Microsoft SharePoint Server 2010 site in a hierarchical tree that is expandable and collapsible. This web part is adapted from my SharePoint Server 2007 version. For something similar that works in SharePoint Foundation 2010, please check out my Site Content Web Part.

Description

The Web Part uses a PortalSiteMapProvider to render the site structure in a hierarchical tree that is expandable and collapsible. The PortalSiteMapProvider is referenced from the site's web.config and is defaulted to be CurrentNavigation, as used in the out-of-the-box "Current Navigation".

It has several public properties:

  • SiteMapProvider - (Site Map Provider) A site map provider of type PortalSiteMapProvider. Default is CurrentNavigation.
  • StartNodeKey - (Starting Site URL) Server-relative URL for a starting sub-site.
    For example: /PressReleases/2010. Default is /, the root site. If set to blank, starting sub-site will be the current site.
  • ExpandMap - (Expand Map?) Expand all nodes on page load. Default is true.
  • IncludeSubSites - (Include sub-sites?) Show sub-sites in node. Valid values are Always, Never and PerWeb. Default is PerWeb, i.e. a per sub-site setting configurable in Site Actions > Navigation (Look and Feel).
  • IncludePages - (Include Pages?) Show pages in nodes. Valid values are Always, Never and PerWeb. Default is PerWeb, i.e. a per sub-site setting configurable in Site Actions > Navigation (Look and Feel).
  • MaxLevels - (Maximum levels) Maximum number of node levels.
  • ListCssClass - CSS class name for the outermost <ul> tag.
  • NodeCssClass - CSS class name for regular hyperlinked nodes.
  • CurrentNodeCssClass - CSS class name for a selected node.
  • NoUrlNodeCssClass - CSS class name for nodes with no URL, like headings.

The Web Part uses two methods to include resources. JavaScript files are treated as Embedded Resources and images are treated as Class Resources. To reference Embedded Resources in code, use Page.ClientScript.GetWebResourceUrl and pass in the file in the form of [Default namespace].[Folder containing resource].[Filename of resource]. In AssemblyInfo.cs, include the file like:

[assembly: System.Web.UI.WebResource
    ("QuestechSystems.SharePoint.Publishing.ClientScripts.SiteMapWebPart.js", 
	"text/javascript")]

Class Resource files are referenced in code by calling SPWebPartManager.GetClassResourcePath. To package them for deployment, a SharePoint 2010 Empty Element is created in Visual Studio 2010. Files are added under the newly created folder with Deployment Type set to ClassResource. Since the project assembly is deployed to GAC, the deployment path will be something like /_wpresources/QuestechSystems.SharePoint.Publishing.SiteMapWebPart/
1.0.0.0__079e23e300376e5b/
.

The Web Part also uses a resource file to store all messages and property attribute UI strings. It demonstrates how to develop a custom class that inherits WebDescriptionAttribute, WebDisplayNameAttribute or CategoryAttribute and returns a localized string from your own Resource Manager.

The supplied Visual Studio 2010 solution includes all the support files you need to build and deploy this Web Part, minus the strong name key file (key.snk). It makes full use of the built-in SharePoint integration. No more third party tools or custom pre and post build scripts are needed to build the SharePoint solution file.

Installation

Open SharePoint 2010 Management Shell, add solution file QuestechSiteMapWebPart.wsp using Add-SPSolution like

Add-SPSolution "C:\QuestechSystems.SiteMapWebPart\bin\Release\QuestechSiteMapWebPart.wsp"

Or using stsadm, add solution file QuestechSiteMapWebPart.wsp like:

stsadm -o addsolution 
    -filename "C:\QuestechSystems.SiteMapWebPart\bin\Release\QuestechSiteMapWebPart.wsp"

Go to SharePoint 2010 Central Administration/System Settings/Manage farm solutions. Deploy the installed solution to selected web applications. In the site collection where the solution is deployed, activate the Site Collection Feature Questech Systems Site Map Web Part. After that, the Site Map Web Part (listed under Questech Systems) should be available for you to add to pages.

CSS can be added to the master page or page layout to enhance styling of the web part. For example if ListCssClass is set to scList, the following definitions will stylize the web part to look like the screenshot above.

.scList, .scList ul
{
    list-style: none;

    padding: 0;
}
.scList, .scList li
{
    margin: 0.66em 0;
}
    
.scList ul
{
    margin: 0.66em 2em;
}

History

  • 19th May, 2010: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Stephen Huen
Web Developer Questech Systems
Canada Canada
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionError when deployig as a sandboxed solutionmemberTariq Afzal14 May '12 - 0:45 
When i deployed this solution as a sandboxed, its give me the following error,
The provider 'AspNetXmlSiteMapProvider' specified for the defaultProvider does not exist
in the providers collection
Tariq Afzal
Software Engineer

QuestionRe: Error when deployig as a sandboxed solutionmemberJuan Sebastian Vanegas6 Jun '12 - 6:04 
I have the same problem, someone could help us with that? Thks!

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 20 May 2010
Article Copyright 2010 by Stephen Huen
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid