Page Layout Shenanigans

I’ve been working on a full trust SharePoint 2010 solution that uses a module to deploy some page layouts to the master page gallery and ran into an interesting scenario…

Setting the scene

I have a feature (version 1) that deploys two page layouts.

Activating the feature deployed the page layouts to the master page gallery as expected:

  • Layout1.aspx (deployed by the feature)
  • Layout2.aspx (deployed by the feature)

Then I manually uploaded an additional page layout to the master page gallery:

  • Layout1.aspx (deployed by the feature)
  • Layout2.aspx (deployed by the feature)
  • Layout3.aspx (uploaded manually)

The problem

Later I updated my feature code (version 2) to deploy an additional two page layouts called Layout3.aspx and Layout4.aspx.

The feature upgrade completed successfully and now the master page gallery contains all four page layouts as specified in version 2 of the feature:

  • Layout1.aspx (deployed by the feature)
  • Layout2.aspx (deployed by the feature)
  • Layout3.aspx (uploaded manually)
  • Layout4.aspx (deployed by the feature)

At this point the problem is that Layout3.aspx still uses the page layout that was manually uploaded (stored in the content database) and not the page layout deployed by the feature (store in the SharePoint root).

Un-ghost in the machine

My initial thought was that in order to point the list item at the page layout deployed by the feature to the SharePoint root we can un-customize the page.

Page layouts can be un-customized via the UI by going to the reset to site definition page (site actions > site settings > site actions > reset to site definition) or using code and calling the SPFile.RevertContentStream method.

Attempting to reset (un-customize) Layout3.aspx presents the following error however:

Cannot revert to the site definition version of this file. It is a custom file and is not part of the site definition.

I confirmed that Layout3.aspx had been deployed to the feature folder in the SharePoint root and it is possible to reset all the other page layouts in this way.

Digging deeper

It was time to fire up SharePoint Manager 2010 and look at the actual items in the master page gallery to determine how things work under the hood…

Looking at the page layout items in the master page gallery there are two properties of interest regarding the “customization” of pages:

The CustomizedPageStatus property is used to indicate whether an item has been customised from its definition and can be set to none, customised or uncustomized.

For Layout3.aspx this property is set to “none” whereas the working page layouts it is set to “uncustomized”.

The vti_setuppath property is set to the path of the file in the SharePoint root.

For Layout3.aspx this property was NOT set indicating that the page layout has no file in the SharePoint root.

These two properties are the reason for the exception when attempting to reset the page layout.

Now we just need to set the CustomizedPageStatus and vti_setuppath properties and we’re off to the races but as it turns out they are read-only so we need to find another way.

Solution

After the long windy road of getting here I chose to use the following technique to “repair” these properties on the Layout3.aspx page layout:

I added another upgrade (version 3 for those keeping count) to my feature:

  • Added another manifest (elementsV3.xml) to the module to deploy the same page layout with a different name (e.g. “Layout3Fix.aspx”).
  • Added a custom upgrade action that uses the SPFile.MoveTo method to replace the old Layout3.aspx with the newly deployed Layout3Fix.aspx

Upgrading the feature to version 3 will now replace the manually uploaded page layout (layout3.aspx) with the page layout from the feature. This restores the two properties discussed previously to the correct values and the page layouts now point to those deployed by the feature in the SharePoint root.

Future updates to the page layouts by solution updates will now be reflected in content pages that use these page layouts.

Advertisements

SharePoint 2010 Service Reference

Mostly for my own reference but here is the list of SharePoint 2010 Windows Services:

Service Description
SPAdminV4 SharePoint 2010 Administration
SPSearch4 SharePoint Foundation Search V4
SPTimerV4 SharePoint 2010 Timer
SPTraceV4 SharePoint 2010 Tracing
SPUserCodeV4 SharePoint 2010 User Code Host
SPWriterV4 SharePoint 2010 VSS Writer
OSearch14 SharePoint Server Search 14
DCLauncher14 Document Conversions Launcher
DCLoadBalancer14 Document Conversions Load Balancer
WebAnalyticsService Web Analytics Service

SharePoint site template reference

When working with SharePoint data from STSADM operations, PowerShell cmdlets or when programming against the SharePoint object model it won’t be long until you need to deal with the internal names for site templates.

I’ve pulled together the default templates that are installed with SharePoint 2010 and 2007 in the following reference:

SharePoint Foundation 2010

Template Name
BLOG#0 Blog
MPS#0 Basic Meeting Workspace
MPS#1 Blank Meeting Workspace
MPS#2 Decision Meeting Workspace
MPS#3 Social Meeting Workspace
MPS#4 Multiple Meeting Workspace
SGS#0 Basic Group Work Site
SGS#1 Blank Group Work Site
STS#0 Team Site
STS#1 Blank Site
STS#2 Document Workspace
WIKI#0 Wiki

SharePoint Server 2010

Template Name
ACCSRV#1 Assets Web Database
ACCSRV#3 Charitable Contributions Web Database
ACCSRV#41 Contacts Web Database
ACCSRV#5 Projects Web Database
BDR#0 Document Center
BICENTERSITE#0 Business Intelligence Center
BLANKINTERNET#2 Publishing Site With Workflow
BLANKINTRANETCONTAINER#0 Publishing Portal
CMSPUBLISHING#0 Publishing Site
ENTERWIKI#0 Enterprise Wiki
OFFILE#1 Records Center
SPSMSITE#0 Personalization Site
SPSMSITEHOST#0 My Site Host
SRCHCEN#0 Enterprise Search Center
SRCHCENTERFAST#0 FAST Search Center
SRCHCENTERLITE#0 Basic Search Center
VISPRUS#0 Visio Process Repository

Windows SharePoint Services 3.0

Template Name
BLOG#0 Blog
MPS#0 Basic Meeting Workspace
MPS#1 Blank Meeting Workspace
MPS#2 Decision Meeting Workspace
MPS#3 Social Meeting Workspace
MPS#4 Multiple Meeting Workspace
STS#0 Team Site
STS#1 Blank Site
STS#2 Document Workspace
WIKI#0 Wiki

SharePoint Server 2007

Template Name
BDR#0 Document Center
BLANKINTERNET#0 Publishing Site
BLANKINTERNET#1 Press Releases Site
BLANKINTERNET#2 Publishing Site with Workflow
BLANKINTERNETCONTAINER#0 Publishing Portal
CENTRALADMIN#0 Central Admin Site
CMSPUBLISHING#0 Publishing Site
GLOBAL#0 Global Template
OFFILE#1 Records Center
OSRV#0 Shared Services Admin Site
PROFILES#0 Profiles
SPS#0 SharePoint Portal Server Site (Obsolete)
SPSCOMMU#0 Community Area Template (Obsolete)
SPSMSITE#0 Personalization Site
SPSMSITEHOST#0 My Site Host
SPSNEWS#0 News Site (Obsolete)
SPSNHOME#0 News Site
SPSPERS#0 SharePoint Portal Server Personal Space
SPSPORTAL#0 Collaboration Portal
SPSREPORTCENTER#0 Report Center
SPSSITES#0 Site Directory
SPSTOC’#0 Contents Area Template (Obsolete)
SPSTOPIC#0 Topic Area Template (Obsolete)
SRCHCEN#0 Search Center with Tabs
SRCHCENTERLITE#0 Search Center
SRCHCENTERLITE#1 Search Center

Other than the native site templates there are also a few others which I’ve frequently encountered in SharePoint environments.

Microsoft Project Server integrates with SharePoint and creates sites based on the Project Workspace (PWS#0) template.

And finally… after the release of WSS 3.0 Microsoft made available a number of additional templates called the Fabulous 40 Application Templates.

Fabulous 40 Application Templates

Template Name
Board#0 Board of Directors
BPR#1 Business Performance Reporting
CASE#0 Case Management for Government Agencies
CLASSROOM MANAGEMENT#0 Classroom Management
CLINIC#0 Clinical Trial Initiation and Management
CAS#1 Competitive Analysis Site
DISCUSSION DATABASE#0 Discussion Database
DIM2#1 Disputed Invoice Management
3#1 Employee Activities Site
BENEFITS#0 Employee Benefits Site
FINAL#1 Employee Training Scheduling and Materials
EQUITY2#0 Equity Research
GCHAN_MAN#0 Manufacturing Process Management
IMC2#1 Integrated Marketing Campaign Tracking
NEWSTORE#0 New Store Opening
PRODUCT#1 Product and Marketing Requirements Planning
RFP V2#0 Request for Proposal
SPORTS#0 Sports League
TEAM ROOM SITE#0 Team Work Site
APP#0 Timecard Management

SharePoint “Send To” Destinations

As part of the document management features in SharePoint 2010 there is a contextual ribbon tab (and context menu) available for each document in a document library. This menu contains an option called “send to” in the Copies section and as the name suggests this will send a copy of the document to a different destination.

image

By default there are two options available under the “send to” menu: other location and create document workspace.

The other location option will allow you to send a copy of a document to another document library or folder.

Send document to other location form

Create document workspace will create a new site based on the Document Workspace template and will copy the document to the new site.

Two additional types of destinations can be configured to appear in the document library “send to” menu.

Another Document Library or Folder

Each document library allows for the configuration of a single “send to” destination. This can be a document library or folder in the same site collection as the source document library.

Since the other location option allows users to copy documents to another document library already this is a means of creating a more convenient shortcut if you need to copy documents to a specific location on a frequent basis.

For example documents might be copied to a folder once they are signed off by a client.

To configure a custom send to destination for a document library navigate to the document library and choose the following options:

Library Tools > Library > Library Settings > Advanced Settings

image

Records Centre

The second target location is a site collection based on the Records Center site template.

SharePoint 2010 provides more flexibility in the configuration of the records centre connection than before and allows us to connect one or more record centres to a web application.

Note: In SharePoint 2007 only a single Records Centre connection could be defined for the entire farm and would show up in send to menus for all document libraries in the farm.

To configure “send to” connections for a web application:

Central Administration > General Application Settings > Configure Send To Connections

Send to connections form

Getting started developing on SharePoint 2010

Here are some free videos providing a developer introduction to working with SharePoint 2010. They cover the following topics:

  • Getting Started: Building Web Parts
  • What developers need to know
  • Building blocks for Web Part Development
  • Accessing Data with Server-Side APIs
  • Accessing Data with Client-Side APIs
  • Accessing External Data with BCS
  • Developing Business Processes
  • Creating Silverlight User Interfaces Solutions
  • Sandbox Solutions for Web Parts
  • Creating Dialogs and Ribbon Controls

http://msdn.microsoft.com/en-gb/sharepoint/ee513147.aspx