Archive for October, 2011

This page is not using a valid page layout in SharePoint 2010

October 18, 2011 Leave a comment

In this post, I’ll show you how to overcome the error ‘This page is not using a valid page layout’ when moving around content from one publishing site collection to another in SharePoint 2010.

It’s a problem I’ve come across a few times as it’s been around since MOSS.  It occurs if the relative path between site collections or web application is different and therefore breaks the link to PageLayout.  For example moving these pages:


to a subsite


will result in an invalid relative link to the pagelayout, in this case it will be http://intranet/sites/wiki/_catalogs/…. so as you can see there is an erroneous sites reference within the link.

Initially it’s best to view the current Pagelayout assigned to each page, to do so you can use this script, replace [Site URL] with the url of the site containing your publishing pages.

$Site = "http://[Site URL]"

$web = Get-SPWeb -Identity $Site
$publishingWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$publishingPages = $publishingWeb.GetPublishingPages()
foreach ($publishingPage in $publishingPages)
  write-host $publishingPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout]

To resolve the issue, I wanted a flexible solution which could work with any pagelayout or even replace them if needed and therefore opted for a script which used a simple search and replace.   In the following script, update the [Site URL], the [Search for] for the string to search for, for example the old link and [Replace with] for the new value, such as the new site.

$Site = "http://[Site URL]"
$SearchFor = "[Search For]"
$ReplaceWith = "[Replace With]"

$web = Get-SPWeb -Identity $Site
$publishingWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$publishingPages = $publishingWeb.GetPublishingPages()
foreach ($publishingPage in $publishingPages)
  $url = $publishingPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout]
  if ($url -match $SearchFor)
    write-host Updating Page Layout for $publishingPage.Name
    $newurl = $url -replace $SearchFor, $ReplaceWith
    $publishingPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout] = $newurl
    $publishingPage.ListItem.File.CheckIn("Corrected page layout URL", [Microsoft.SharePoint.SPCheckinType]::MajorCheckIn);
Categories: Publishing, SharePoint

Create a blank publishing page in SharePoint 2010 for a print view or hosting in an iFrame

October 11, 2011 Leave a comment

There are a few occassions when a page’s content could be useful without the associated branding and navigation elements being visible.  For example if you want to create a print view or host SharePoint content in an iFrame.  In my case I wanted to host the Organization Browser web part within an iFrame using a Content Editor Web Part.  This would enable me to access the same page on multiple sites, getting different content by setting querystring values in the CEWP and overcoming the issue of adding querystrings to URLs breaking SharePoint navigation.

First you need to create a new masterpage using SharePoint Designer, to do this take a copy of your existing custom masterpage or default.master and name it blank.master. Edit the file in Advanced Mode and find the main table which starts with <table class=”ms-main”.  Now add this style=”display:none” tag to the end.  It should look something like this:

<table cellpadding=”0″ cellspacing=”0″ border=”0″ width=”100%” height=”100%” style=”display:none”>

Next find this content holder <asp:ContentPlaceHolder id=”PlaceHolderMain” runat=”server”></asp:ContentPlaceHolder> and copy this to the clipboard, delete it from it’s original location and place it under the closing tag for the main table.  Also, to avoid scrollbars appearing in my iFrame, I amended to the body tag to set scroll=”no”.

Checkin, publish and approve your new masterpage.  Now if you haven’t already, create the content which you wish to host in the blank master page, then return to SharePoint Designer.  Next we need to detach the content page from it’s Page Layout, so open the library which contains your content, select the file, right click  and choose Detach from Page Layout then click Yes to the warning.  If the library is under source control, click Yes to check it out.  Now right click again and choose Edit file in Advanced Mode.

Now replace this line:

<%@ Page language=”C#” Inherits=”Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=,Culture=neutral,PublicKeyToken=71e9bce111e9429c” meta:progid=”SharePoint.WebPartPage.Document” meta:webpartpageexpansion=”full” %>

with this:

<%@ Page language=”C#” MasterPageFile=”~/_catalogs/masterpage/blank.master” Inherits=”Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=,Culture=neutral,PublicKeyToken=71e9bce111e9429c” meta:progid=”SharePoint.WebPartPage.Document” meta:webpartpageexpansion=”full” %>

Save the file and if all is well, you’ll see the content without branding and navigation.

As you can see from the changes, this content now inherits from Microsoft.SharePoint.WebPartPages.WebPartPage which enables the MasterPage to be set.  With Microsoft.SharePoint.Publishing.PublishingLayoutPage this isn’t possible without custom code overriding OnPreInit.

%d bloggers like this: