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.
The user control uses the SharePoint Publishing API
PublishingWeb.GetPages to return a list of pages in a publishing sub-site. It has several
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.
SortField - Sorting (internal) field name.
SortOrder - Sort in ascending order?
True for ascending and
False for descending.
ContentType - If provided, only page links of the specified content type will be shown.
RowLimit - The maximum number of page links to show.
public properties get the value of a "page field".
fieldName is the display name of a page field.
GetFieldValue(RepeaterItem item, string fieldName)
GetFieldValue(Container, "Rollup Image") returns the HTML content of the
Rollup Image field.
GetFieldText(RepeaterItem item, string fieldName)
GetFieldText(Container, "Server Relative URL") returns the page URL.
GetFieldText(RepeaterItem item, string fieldName, bool htmlEncoded)
GetFieldText(Container, "Title", true) returns the page Title field
GetFieldText(RepeaterItem item, string fieldName, int maxChars)
GetFieldText(RepeaterItem item, string fieldName, int maxChars, bool htmlEncoded)
GetFieldText(Container, "Page Content", 200, true) returns the text (non-HTML) content of the Page Content field, up to a maximum of 200 characters,
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:
<asp:Repeater ID="SummaryLinksRepeater1" runat="server">
"<%# GetFieldText(Container, "Server Relative URL") %>">
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
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.
stsadm, install solution file QuestechSummaryLinks.wsp in \Deployments\Solution\:
stsadm -o addsolution -filename QuestechSummaryLinks.wsp
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:
<%@ Register TagPrefix="uc1" TagName="SummaryLinks"
- 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
public properties to get value of a page field
- Added support to show all page field types
- V1.2 - 2008.04.13
- Renamed property
- Renamed property
- Included sample Visual Studio 2005 solution for compiling and deploying the user control
- Updated installation instructions
- V1.1 - 2007.09.23
- Added property
- Renamed properties
- Added resource file for property attribute UI
strings and error messages
- V1.01 - 2007.03.24 - Restructured code
- V1.0 - 2006.12.07 - Base