Click here to Skip to main content
15,114,081 members
Articles / Web Development / ASP.NET
Posted 7 Dec 2006


58 bookmarked

Site Map Web Part for Microsoft Office SharePoint Server (MOSS)

Rate me:
Please Sign up or sign in to vote.
4.18/5 (7 votes)
28 Jul 2010CPOL5 min read
Displays the site structure in a hierarchical tree that is expandable and collapsible.

Screenshot - sample.gif


For use in Microsoft Office SharePoint Server (MOSS) 2007, this Web Part displays the site structure in a hierarchical tree that is expandable and collapsible. It is based on my Site Map custom control written for Content Management Server 2002.

A WSS 3.0 version is available separately here. For a version to work in SharePoint Server 2010, please check out Site Map Web Part (SharePoint Server 2010).


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 CurrentNavSiteMapProvider, 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 CurrentNavSiteMapProvider.
  • StartNodeKey - (Starting Site URL) Server-relative URL for a starting sub-site. For example: /PressReleases/2006. Default is the root 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 the Modify Navigation Site Actions menu.
  • 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 the Modify Navigation Site Actions menu.
  • 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. Images are treated as Class Resources, and JavaScript files are treated as Embedded Resources. To package images as Class Resources in a Solution, include them in the Manifest.xml, like:

<?xml version="1.0" encoding="utf-8" ?>
<Solution xmlns=""
    SolutionId="SolutionGuid" ResetWebServer="TRUE">
        <Assembly Location="QuestechSystems.SharePoint.Publishing.SiteMapWebPart.dll"
                <ClassResource Location="images\node-closed.gif" />
                <ClassResource Location="images\node-open.gif" />
                <ClassResource Location="images\node.gif" />
                    Culture=neutral, PublicKeyToken=AssemblyToken"
                    TypeName="*" Safe="True" />
        <FeatureManifest Location="QuestechSiteMapWebPart\Feature.xml" />

In solution deployment, resource files are deployed based on the assembly destination. For assemblies deployed to the bin directory, resource files are copied to an assembly subdirectory under the wpresources directory of the destination IIS Web application. For assemblies deployed to GAC, resource files are copied to an assembly subdirectory under the virtual directory _wpresources. In the code, a path to resource files is obtained from SPWebPartManager.GetClassResourcePath.

For the JavaScript file SiteMapWebPart.js, set its build action to "Embedded Resource" in Visual Studio 2008. In code, reference the file using Page.ClientScript.GetWebResourceUrl. You will need to pass in the file in the form of [Default namespace].[Folder containing resource].[Filename of resource]. In AssemblyInfo.cs, include SiteMapWebPart.js in the same format like:

[assembly: System.Web.UI.WebResource
    SiteMapWebPart.js", "text/javascript")]

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 sample Visual Studio 2008 solution includes all the support files you need to build and deploy this Web Part, minus strong name key files (*.snk). It contains three projects: Deployment, Features, and SharePoint.Publishing. The SharePoint.Publishing project contains source codes for the Web Part. The Features project contains all the features to support the SharePoint.Publishing project. The Deployment project contains a pre-build script to aggregate all the files needed for deployment. It contains a Solution directory where a WSP file is generated and deployed by a post-build script.

This structure of Visual Studio solution and projects is scalable to full blown MOSS/WSS development and deployment. You could add additional projects like SharePoint for WSS or MOSS non-publishing development, or SharePoint.ApplicationPages for customization of administrative layout pages. Within your projects, you could have other custom components like user and Web controls, custom fields, feature receivers, etc.


Using stsadm, install the solution file QuestechSiteMapWebPart.wsp in \Deployments\Solution\:

stsadm -o addsolution -filename QuestechSiteMapWebPart.wsp

Go to SharePoint Central Administration/Operations/Global Configuration-Solution Management. Deploy the installed solution to selected Web applications. In the site collection where the solution is deployed, activate Feature Questech Systems Site Map Web Part. After that, the Site Map Web Part should be available for you to add to pages.


  1. CodeGuru: Write Custom WebParts for SharePoint 2007
  2. Eric Stallworth: How to Build a Solution Pack (WSP)
  3. Stephen Huen: Microsoft Content Management Server Site Map control (C#)


  • V1.6 - 2010.03.12
    • Renamed .SiteMap to .SiteMapWebPart throughout the solution. The new names are QuestechSiteMapWebPart.wsp, SiteMapWebPart.dll, and SiteMapWebPart.js. This should resolve the issue of image icons not showing up in some system configurations due to IIS blocking the .SiteMap extension in the image paths.
  • V1.5 - 2009.05.22
    • Converted Visual Studio solution projects to version 2008.
    • New SharePoint solution QuestechSiteMap.wsp and assembly QuestechSystems.SharePoint.Publishing.SiteMap.dll. This allows my other sample solutions in CodeProject to co-exist with this Web Part.
    • Renamed Feature from QuestechPublishingWebParts to QuestechSiteMapWebPart.
  • V1.4 - 2008.04.12
    • Included sample Visual Studio 2005 solution for compiling and deploying the Web Part.
    • Updated installation instructions.
  • V1.31 - 2007.10.02
    • Removed InstallPackage.bat as it confuses people that a compilation is not needed.
  • V1.3 - 2007.09.18
    • Namespace and class name changed.
    • Added properties SiteMapProvider and IncludeSubSites.
    • Added resource file for property attribute UI strings and error messages.
    • Removed sitemap.wsp from sample files.
  • V1.21 - 2007.04.25
    • Removed limit of 50 nodes/sites at each level.
  • V1.2 - 2007.04.20
    • Removed restriction on "Publishing" site types only.
  • V1.12 - 2007.04.11
    • Fixed the sitemap.wsp solution install error.
  • V1.11 - 2007.03.20
    • Fixed missing icon images.
    • Better error handling.
  • V1.1 - 2007.03.06
    • Extracted JavaScript code to external *.js file as an embedded resource.
    • Relocated icon images to be used as class resource.
  • V1.0 - 2006.12.07 - Base.


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


About the Author

Stephen Huen
Software Developer (Senior)
Canada Canada
A Microsoft Certified Professional Developer and Technology Specialist.

Experience and expertise in SharePoint 2016 / 2013 / 2010 / 2007.

Role ranges from a developer in a multi-person team to a solution consultant with expert-level skills, leading a project to completion status.

Proven experience working effectively in a team environment and a self-managed environment.

Comments and Discussions

BugError :- A Web Part or Web Control can not be import in this page. type is not a safe control Pin
Gaurav12227-Dec-11 19:52
MemberGaurav12227-Dec-11 19:52 
QuestionNo site map on a Publishing site with Custom Master page Pin
BlueSky2013-Apr-11 7:07
MemberBlueSky2013-Apr-11 7:07 
AnswerRe: No site map on a Publishing site with Custom Master page Pin
BlueSky2015-Apr-11 4:45
MemberBlueSky2015-Apr-11 4:45 
GeneralQuick Launch disappears Pin
tjohn434321-Feb-11 11:19
Membertjohn434321-Feb-11 11:19 
GeneralSite Map Performance Pin
jumbojum30-Apr-10 8:05
Memberjumbojum30-Apr-10 8:05 
QuestionPath to images cannot be served because it has .SiteMap in it Pin
mkamoski11-Mar-10 5:44
Membermkamoski11-Mar-10 5:44 
AnswerRe: Path to images cannot be served because it has .SiteMap in it Pin
Stephen Huen15-Mar-10 14:26
MemberStephen Huen15-Mar-10 14:26 
GeneralAnonymous user problem Pin
Member 353936128-Dec-09 0:07
MemberMember 353936128-Dec-09 0:07 
GeneralDoesn't have indentation Pin
Member 449799126-Jul-09 8:15
MemberMember 449799126-Jul-09 8:15 
GeneralRe: Doesn't have indentation Pin
Curtis Shirley28-Aug-09 8:32
MemberCurtis Shirley28-Aug-09 8:32 
GeneralIneed to localized to another language Pin
Ali M. Hussein15-Jul-09 6:17
MemberAli M. Hussein15-Jul-09 6:17 
GeneralBroken images Pin
cheong69@yahoo.com19-Jun-09 16:52
Membercheong69@yahoo.com19-Jun-09 16:52 
GeneralRe: Broken images Pin
Stephen Huen29-Jun-09 14:08
MemberStephen Huen29-Jun-09 14:08 
GeneralRe: Broken images Pin
cheong69@yahoo.com5-Jul-09 16:24
Membercheong69@yahoo.com5-Jul-09 16:24 
GeneralRe: Broken images Pin
Stephen Huen7-Jul-09 18:05
MemberStephen Huen7-Jul-09 18:05 
GeneralRe: Broken images Pin
Member 465313027-Jul-09 6:35
MemberMember 465313027-Jul-09 6:35 
GeneralRe: Broken images Pin
4wildkat2-Oct-09 6:40
Member4wildkat2-Oct-09 6:40 
GeneralRe: Broken images Pin
charmingbalu26-Oct-09 2:18
Membercharmingbalu26-Oct-09 2:18 
QuestionPublishing as well as non publishing websites Pin
.Netter30-Jan-09 4:51
Member.Netter30-Jan-09 4:51 
GeneralDeep Down Pin
kundankoman22-Jan-09 8:43
Memberkundankoman22-Jan-09 8:43 
General"Cannot import this webpart" Pin
RickyTH3-Nov-08 22:05
MemberRickyTH3-Nov-08 22:05 
QuestionCss class Pin
lattelis11-Jun-08 3:30
Memberlattelis11-Jun-08 3:30 
QuestionRe: Css class Pin
Amna-Omer23-Mar-11 16:08
MemberAmna-Omer23-Mar-11 16:08 
AnswerRe: Css class Pin
Amna-Omer23-Mar-11 20:44
MemberAmna-Omer23-Mar-11 20:44 
GeneralUnable to open the solution Pin
sunil_limje3-May-08 2:09
Membersunil_limje3-May-08 2:09 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.