Click here to Skip to main content
15,867,568 members
Articles / Web Development / ASP.NET

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

Rate me:
Please Sign up or sign in to vote.
3.80/5 (4 votes)
25 May 2009CPOL4 min read 61.5K   186   19   4
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.

  • C#
    GetFieldValue(RepeaterItem item, string fieldName)

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

  • C#
    GetFieldText(RepeaterItem item, string fieldName)

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

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

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

  • C#
    GetFieldText(RepeaterItem item, string fieldName, int maxChars)
  • C#
    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.NET
<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:

ASP.NET
...
<%@ 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)


Written By
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

 
GeneralLeak Pin
ultram16-Dec-09 8:36
ultram16-Dec-09 8:36 
Generalnice article Pin
M i s t e r L i s t e r6-Apr-08 14:48
M i s t e r L i s t e r6-Apr-08 14:48 
Questioncontrol into a DLL Pin
maparicio5-Sep-07 9:52
maparicio5-Sep-07 9:52 
AnswerRe: control into a DLL Pin
Stephen Huen5-Sep-07 20:53
Stephen Huen5-Sep-07 20:53 

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.