Introduction

For use in a Microsoft Office SharePoint Server (MOSS) 2007 Publishing Web site, this user control displays a summary list of page links for a sub-site and, optionally, page field values like Page Content snippet or Rollup Image. It offers features similar to the out-of-the-box Content Query Web Part, but is written as a user control and therefore allows easy customization of the UI.

Description

The user control uses the SharePoint Publishing API PublishingWeb.GetPages to return a list of pages in a publishing sub-site. It has several public properties:

RepeaterID - The ID of the Repeater control to show repeating page links.

SiteUrl - The URL of the sub-site to show page links. For example: /PressReleases/2007. If left empty, the current site will be used.

For example GetFieldText(Container, "Page Content", 200, true) returns the text (non-HTML) content of the Page Content field, up to a maximum of 200 characters, HtmlEncoded.

The user control binds the matched list of publishing pages to a Repeater control. You can define multiple repeaters with different UI or formatting in SummaryLinks.ascx. The property RepeaterID determines which repeater to bind the publishing pages to. This design allows different rendering of page links in different site master pages or page layouts. For example, in Summarylinks.ascx, you can have something like:

By design, the default or welcome page of a sub-site is excluded from the list of publishing pages. In the code, I need to raise the security context by creating a site collection using SystemAccount.UserToken to obtain the default page of a sub-site. Otherwise, the user control will prompt for login in the browser when it is running in an anonymous site.

The user control also uses a resource file to store all messages and property attribute UI strings. It demonstrates how to develop a custom class that inherits CategoryAttribute or DescriptionAttribute 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 user control, minus strong name key files (*.snk). It contains two projects: Deployment and SharePoint.Publishing. The SharePoint.Publishing project contains source codes for the user control. 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 probably an overkill for a single user control but is designed to be 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 web controls, web parts, custom fields, feature receivers, etc.

Installation

Go to SharePoint Central Administration/Operations/Global Configuration-Solution Management. Deploy the installed solution to selected Web applications. To insert the user control to a publishing page, modify the appropriate master page or page layout as follows:

History

V1.4 - 2009.05.22

Converted Visual Studio solution projects to version 2008

New SharePoint Solution QuestechSummaryLinks.wsp and assembly QuestechSystems.SharePoint.Publishing.SummaryLinks.dll. This allows my other sample solutions in CodeProject to co-exist with this user control.

V1.3 - 2008.09.02

Revamped public properties to get value of a page field

Added support to show all page field types

V1.2 - 2008.04.13

Renamed property StartSiteUrl to SiteUrl

Renamed property Ascending to SortOrder

Included sample Visual Studio 2005 solution for compiling and deploying the user control