5,277,262 members and growing! (17,225 online)
Email Password   helpLost your password?
Enterprise Systems » SharePoint Server » Web Parts     Intermediate License: The Code Project Open License (CPOL)

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

By Stephen Huen

Displays the site structure in a hierarchical tree that is expandable and collapsible
C#, XML, Windows, .NET 2.0, .NET, ASP.NET, VS, VS2005, Dev

Posted: 7 Dec 2006
Updated: 15 Apr 2008
Views: 56,356
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
4 votes for this Article.
Popularity: 2.50 Rating: 4.16 out of 5
1 vote, 25.0%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
0 votes, 0.0%
4
3 votes, 75.0%
5
Screenshot - sample.gif

Introduction

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.

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 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 Manifest.xml, like:

<?xml version="1.0" encoding="utf-8" ?>
<Solution xmlns="http://schemas.microsoft.com/sharepoint/"
    SolutionId="SolutionGuid" ResetWebServer="TRUE">
    <Assemblies>
        <Assembly Location="QuestechSystems.SharePoint.Publishing.dll"
            DeploymentTarget="GlobalAssemblyCache">
            <ClassResources>
                <ClassResource Location="images\node-closed.gif" />
                <ClassResource Location="images\node-open.gif" />
                <ClassResource Location="images\node.gif" />
            </ClassResources>
            <SafeControls>
                <SafeControl Assembly="QuestechSystems.SharePoint.Publishing,
                    Version=1.0.0.0,
                    Culture=neutral, PublicKeyToken=AssemblyToken"
                    Namespace=
                    "QuestechSystems.SharePoint.Publishing.
                    WebControls.WebParts"
                    TypeName="*" Safe="True" />
            </SafeControls>
        </Assembly>
    </Assemblies>
    <FeatureManifests>
        <FeatureManifest Location="QuestechPublishingWebParts\Feature.xml" />
    </FeatureManifests>
</Solution>

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 virtual directory _wpresources. In the code, a path to resource files is obtained from SPWebPartManager.GetClassResourcePath.

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

[assembly: System.Web.UI.WebResource
    ("QuestechSystems.SharePoint.Publishing.WebControls.
    WebParts.SiteMap.SiteMap.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.

Installation

The sample Visual Studio 2005 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.

Of course you can install the Web part as is without further customization. Using stsadm, install the solution file QuestechSolution.wsp in \Deployments\Solution\:

stsadm -o addsolution -filename QuestechSolution.wsp

Then go to SharePoint Central Administration/Operations/Global Configuration-Solution Management and deploy the solution to selected Web applications. In the site collection where the solution is deployed, activate the feature "Questech Systems Publishing Web Parts". After that, the Site Map Web Part should be available for you to add to pages.

References

  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#)

History

  • 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 sitemap.wsp solution install error
  • V1.11 - 2007.03.20 - Fixed missing icon images. Better error handling
  • V1.1 - 2007.03.06 - Extracted JavaScript codes to external *.js file as embedded resource. Relocated icon images to be used as class resource
  • V1.0 - 2006.12.07 - Base

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



Occupation: Web Developer
Company: Questech Systems
Location: Canada Canada

Other popular SharePoint Server articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 68 (Total in Forum: 68) (Refresh)FirstPrevNext
Subject  Author Date 
QuestionCss classmemberlattelis3:30 11 Jun '08  
GeneralUnable to open the solutionmembersunil_limje2:09 3 May '08  
GeneralRe: Unable to open the solutionmemberStephen Huen7:15 4 May '08  
GeneralRe: Unable to open the solutionmembersunil_limje0:40 5 May '08  
GeneralRe: Unable to open the solutionmemberStephen Huen7:06 5 May '08  
GeneralRe: Unable to open the solutionmembersunil_limje22:17 6 May '08  
GeneralRe: Unable to open the solutionmemberStephen Huen7:39 7 May '08  
GeneralLicence terms?memberAntti802:30 2 Apr '08  
QuestionInvalid SiteMapProvider: SiteMapDataSource1memberHenrik Weimenhog23:35 2 Mar '08  
GeneralRe: Invalid SiteMapProvider: SiteMapDataSource1memberStephen Huen13:40 10 Mar '08  
GeneralHow tomembercarlosfocker9:27 23 Jan '08  
GeneralBuild errormemberSharePointBloke14:33 17 Jan '08  
GeneralRe: Build errormemberSharePointBloke23:57 17 Jan '08  
GeneralRe: Build errormemberSharePointBloke0:17 18 Jan '08  
GeneralWebpart ErrormemberGregS44213:04 7 Nov '07  
GeneralRe: Webpart ErrormemberStephen Huen13:19 7 Nov '07  
GeneralRe: Webpart ErrormemberGregS44214:33 7 Nov '07  
GeneralRe: Webpart ErrormemberStephen Huen22:29 7 Nov '07  
GeneralRe: Webpart ErrormemberGregS4428:59 8 Nov '07  
GeneralRe: Webpart ErrormemberStephen Huen9:19 8 Nov '07  
GeneralRe: Webpart ErrormemberGregS4429:35 8 Nov '07  
QuestionSolution filememberRichard Fennell4:40 1 Oct '07  
AnswerRe: Solution filememberStephen Huen5:52 1 Oct '07  
QuestionRe: Solution filememberAntonio Baros Afonso8:04 8 Dec '07  
Generalinstallmembercowdogs4:01 25 Sep '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 15 Apr 2008
Editor: Sean Ewington
Copyright 2006 by Stephen Huen
Everything else Copyright © CodeProject, 1999-2008
Web08 | Advertise on the Code Project