Click here to Skip to main content
Click here to Skip to main content
Go to top

Summary Links User Control for Microsoft Office SharePoint Server (MOSS)

, 25 May 2009
Rate this:
Please Sign up or sign in to vote.
Displays a summary list of page links for a sub-site
1.gif

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.
  • SortField - Sorting (internal) field name.
    For example: Created, Modified, PublishingStartDate, Title.
  • 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.

The following public properties get the value of a "page field". fieldName is the display name of a page field.

  • GetFieldValue(RepeaterItem item, string fieldName)

    For example GetFieldValue(Container, "Rollup Image") returns the HTML content of the Rollup Image field.

  • GetFieldText(RepeaterItem item, string fieldName)

    For example GetFieldText(Container, "Server Relative URL") returns the page URL.

  • GetFieldText(RepeaterItem item, string fieldName, bool htmlEncoded)

    For example GetFieldText(Container, "Title", true) returns the page Title field HtmlEncoded.

  • GetFieldText(RepeaterItem item, string fieldName, int maxChars)
  • GetFieldText(RepeaterItem item, string fieldName, int maxChars, bool htmlEncoded)

    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:

<asp:Repeater ID="SummaryLinksRepeater1" runat="server">
    <HeaderTemplate>
        <ul>
    </HeaderTemplate>
    <ItemTemplate>

        <li>
            <div>
                <a href=
                     "<%# 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 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

Using 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"
    Src="~/_controltemplates/Questech/SummaryLinks.ascx" %>
...
...
<uc1:SummaryLinks ID="SummaryLinks" RepeaterID="SummaryLinksRepeater"

    SiteUrl="" SortField="Title"
    SortOrder="True" ContentType="Article Page" runat="server" />

...

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
    • Updated installation instructions
  • V1.1 - 2007.09.23
    • Added property RepeaterID
    • Renamed properties SortOrder to Ascending and MaxPages to RowLimit
    • Added resource file for property attribute UI strings and error messages
  • V1.01 - 2007.03.24 - Restructured code
  • 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)

Share

About the Author

Stephen Huen
Software Developer (Senior)
Canada Canada
A Microsoft Certified Professional Developer and Technology Specialist.
 
Experience and expertise in SharePoint 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.
Follow on   LinkedIn

Comments and Discussions

 
GeneralLeak Pinmemberultram16-Dec-09 8:36 
FYI. This code has a memory leak.
I've found this fix and changed the code to the following
http://blogs.msdn.com/rogerla/archive/2009/01/28/updated-publishingweb-getvariation-dispose-guidance.aspx[^]
PublishingWeb publishingSite = null;
                        try
                        {
                            publishingSite = PublishingWeb.GetPublishingWeb(site);
                            List<PublishingPage> pages = GetPages(publishingSite, GetQueryCaml(), _rowLimit);
                            repeater.Visible = true;
                            repeater.DataSource = pages;
                            repeater.DataBind();
                        }
                        finally
                        {
                            if (publishingSite != null)
                                publishingSite.Close();
 
                        }

Generalnice article PinmemberM i s t e r L i s t e r6-Apr-08 14:48 
Questioncontrol into a DLL Pinmembermaparicio5-Sep-07 9:52 
AnswerRe: control into a DLL PinmemberStephen Huen5-Sep-07 20:53 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140905.1 | Last Updated 25 May 2009
Article Copyright 2006 by Stephen Huen
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid