![]() |
Enterprise Systems »
SharePoint Server »
General
Intermediate
License: The Code Project Open License (CPOL)
Summary Links User Control for Microsoft Office SharePoint Server (MOSS)By Stephen HuenDisplays a summary list of page links for a sub-site |
C#, Windows, .NET (.NET 2.0), ASP.NET, Visual Studio (VS2008), Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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 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. SortField - Sorting (internal) field name. 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.
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" />
...
public properties to get value of a page field StartSiteUrl to SiteUrl Ascending to SortOrder RepeaterID SortOrder to Ascending and MaxPages to RowLimit strings and error messages | You must Sign In to use this message board. | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 25 May 2009 Editor: Deeksha Shenoy |
Copyright 2006 by Stephen Huen Everything else Copyright © CodeProject, 1999-2009 Web21 | Advertise on the Code Project |