SharePoint.DesignFactory.ContentFiles–building WCM sites

Posted by svdoever on ASP.net Weblogs See other posts from ASP.net Weblogs or by svdoever
Published on Sat, 26 May 2012 21:09:45 GMT Indexed on 2012/05/30 16:43 UTC
Read the original article Hit count: 840

One of the use cases where we use the SharePoint.DesignFactory.ContentFiles tooling is in building SharePoint Publishing (WCM) solutions for SharePoint 2007, SharePoint 2010 and Office365.

Publishing solutions are often solutions that have one instance, the publishing site (possibly with subsites), that in most cases need to go through DTAP.

If you dissect a publishing site, in most case you have the following findings:

  1. The publishing site spans a site collection
  2. The branding of the site is specified in the root site, because:
    • Master pages live in the root site (/_catalogs/masterpage)
    • Page layouts live in the root site (/_catalogs/masterpage)
    • The style library lives in the root site ( /Style Library) and contains images, css, javascript, xslt transformations for your CQWP’s, …
    • Preconfigured web parts live in the root site (/_catalogs/wp)
  3. The root site and subsites contains a document library called Pages (or your language-specific version of it) containing publishing pages using the page layouts and master pages
  4. The site collection contains content types, fields and lists

When using the SharePoint.DesignFactory.ContentFiles tooling it is very easy to create, test, package and deploy the artifacts that can be uploaded to the SharePoint content database. This can be done in a fast and simple way without the need to create and deploy WSP packages. If we look at the above list of artifacts we can use SharePoint.DesignFactory.ContentFiles for master pages, page layouts, the style library, web part configurations, and initial publishing pages (these are normally made through the SharePoint web UI).

Some artifacts like content types, fields and lists in the above list can NOT be handled by SharePoint.DesignFactory.ContentFiles, because they can’t be uploaded to the SharePoint content database. The good thing is that these artifacts are the artifacts that don’t change that much in the development of a SharePoint Publishing solution. There are however multiple ways to create these artifacts:

  1. Use paper script: create them manually in each of the environments based on documentation
  2. Automate the creation of the artifacts using (PowerShell) script
  3. Develop a WSP package to create these artifacts

I’m not a big fan of the third option (see my blog post Thoughts on building deployable and updatable SharePoint solutions). It is a lot of work to create content types, fields and list definitions using all kind of XML files, and it is not allowed to modify these artifacts when in use. I know… SharePoint 2010 has some content type upgrade possibilities, but I think it is just too cumbersome.

The first option has the problem that content types and fields get ID’s, and that these ID’s must be used by the metadata on for example page layouts. No problem for SharePoint.DesignFactory.ContentFiles, because it supports deploy-time resolving of these ID’s using PowerShell. For example consider the following metadata definition for the page layout contactpage-wcm.aspx.properties.ps1:

Metadata page layout
  1. # This script must return a hashtable @{ name=value; ... } of field name-value pairs
  2. # for the content file that this script applies to.
  3. # On deployment to SharePoint, these values are written as fields in the corresponding list item (if any)
  4. # Note that fields must exist; they can be updated but not created or deleted.
  5. # This script is called right after the file is deployed to SharePoint.
  6.  
  7. # You can use the script parameters and arbitrary PowerShell code to interact with SharePoint.
  8. # e.g. to calculate properties and values at deployment time.
  9.  
  10. param([string]$SourcePath, [string]$RelativeUrl, $Context)
  11. @{
  12.     "ContentTypeId" = $Context.GetContentTypeID('GeneralPage');
  13.     "MasterPageDescription" = "Cloud Aviator Contact pagelayout (wcm - don't use)";
  14.     "PublishingHidden" = "1";
  15.     "PublishingAssociatedContentType" = $Context.GetAssociatedContentTypeInfo('GeneralPage')
  16. }

The PowerShell functions GetContentTypeID and GetAssociatedContentTypeInfo can at deploy-time resolve the required information from the server we are deploying to.

I personally prefer the second option: automate creation through PowerShell, because there are PowerShell scripts available to export content types and fields.

An example project structure for a typical SharePoint WCM site looks like:

image

Note that this project uses DualLayout.

So if you build Publishing sites using SharePoint, checkout out the completely free SharePoint.DesignFactory.ContentFiles tooling and start flying!

© ASP.net Weblogs or respective owner

Related posts about sharepoint

Related posts about SharePoint.DesignFactory.ContentFiles