PANVEGA’s Blog

DotNet Development, SharePoint Customizing, Silverlight, MS Infrastructure and other tips and tricks

Deployment for a Custom SP PageLayout

Posted by PANVEGA on June 25, 2009

In this post I gonna explain in a few steps how to build a SharePoint Feature for a PageLayout. To do this, I needed to create a new page layout based on an existing layout, make this part of a feature and pull in all the bits and pieces necessary to deploy this as a feature.

First I copied a default PageLayout (Welcome Page) with a Fields from this Content Type.The Content Type Group is the default Page Layout. To do This opnen the _catalogs with the SP Designer. Now you have the basic aspx files you will modify and put back into SharePoint as a feature. Open the aspx page in an appropriate editor. Make the appropriate modifications and save the file.

Now it is time building the Solution:

1. Create two new files in any editor: “feature.xml” and “manifest.xml”

In your manifest.xml you actually only reference to your feature.xml

<Feature
Id=”{905041E9-E664-47f6-B4E0-EA5CAA85B6C4}”
Title=”Content Deplyment”
Description=”Deployes the MasterPage,PageLayout,JavaScripts,CSS and Images”
Hidden=”FALSE”
Scope=”Site” ActivateOnDefault=”False”
xmlns=”http://schemas.microsoft.com/sharepoint/”&gt;

<ElementManifests>
<ElementManifest Location=”elements.xml”/>
<ElementFile Location=”RZB.master”/>
<ElementFile Location=”Styles\IE7.css”/>
<ElementFile Location=”Scripts\fontsize.js”/>
<ElementFile Location=”PageLayout\Page_Layout.aspx”/>
<ElementFile Location=”Images\aktmenue.gif”/>
</ElementManifests>
</Feature>

You see in my feature.xml I refrenced to all appropriate files I need to deploy the content to the disk. First I builded a .wsp file by using the .ddf file. Id is a new GUID you generate from Visual Studio.

Scope means the level where this will be used, not the level at which it becomes available for items below it. So “Site” scope means it will be installed at the site collection level and used at the site level.

PageLayoutProperties

2. elements.xml

  • At the module level (collection of files to deploy to a particular location in SharePoint), we specify the URL and whether the files should only be deployed to the root web or to all webs in the site collection. At the file level, attributes for the master pages.
  • In order to access the files through the SP Designer you have to deploy the content in the way above.
  • IgnoreIfAlreadyExists‘ – should be true if we want to overwrite an existing file of this name, false if not.
  • Type’ – should be ‘GhostableInLibrary’ for files which exist in a document library such as the Pages, Style Library or Master Page Gallery libraries which exist in a SharePoint publishing site.

Note: In terms of the GhostableInLibrary setting, this applies to any file in SharePoint which has an entry in a document library but also exists on the filesystem. Hence this can apply to master pages as well as files in the Style Library.
The reason is due to the ghosted/unghosted (customized/uncustomized) concept of files in SharePoint. The files which are changed in the Style Library have already been customized, and have therefore been copied into the database. Therefore, amending the copy on the filesystem will not change anything in SharePoint.

Here is the structure from the Solution folder:

FeatureStructure

<Elements xmlns=”http://schemas.microsoft.com/sharepoint/&#8221; >

<Module Name=”MasterPages” List=”116″ Url=”_catalogs/masterpage” RootWebOnly=”TRUE”>
<File Url=”RZB.master” Type=”GhostableInLibrary” IgnoreIfAlreadyExists=”TRUE” >
<Property Name=”ContentType” Value=”$Resources:cmscore,contenttype_masterpage_name;” />
<Property Name=”Title”  Value=”RZB Master Page” />
<Property Name=”MasterPageDescription” Value=”RZB default Master Page” />
</File>
</Module>
<Module Name=”Images” Path=”Images” List=”101″ Url=”Style Library/Images/MyFolder” RootWebOnly=”TRUE”>
<File Url=”aktmenue.gif” Type=”GhostableInLibrary” IgnoreIfAlreadyExists=”TRUE”/>
</Module>

<!– Style Sheet Module –>
<Module Name=”Stylesheets” Path=”Styles”  List=”101″ Url=”Style Library/MyFolder”>
<File Url=”IE7.css” Type=”GhostableInLibrary” IgnoreIfAlreadyExists=”TRUE”/>
</Module>

<Module Name=”Scripts” Path=”Scripts”  List=”101″ Url=”Style Library/Scripts”>
<File Url=”fontsize.js” Type=”GhostableInLibrary” IgnoreIfAlreadyExists=”TRUE” />
</Module>

<Module Name=”Pages” Path=”PageLayout” Url=”_catalogs/masterpage” RootWebOnly=”TRUE”>
<File Url=”My_Page_Layout.aspx” IgnoreIfAlreadyExists=”TRUE” Type=”GhostableInLibrary”>
<Property Name=”PublishingAssociatedContentType”
Value=”;#Welcome Page;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064DEA0F50FC8C147B0B6EA0636C4A7D4;#” />
<Property Name=”Title”  Value=”My PageLayout” />
<Property Name=”MasterPageDescription” Value=”Default PageLayout” />
<Property Name=”ContentType” Value=”$Resources:cmscore,contenttype_pagelayout_name;” />
<Property name=”PublishingPreviewImage” value=”~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/ArticleLinks.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/ArticleLinks.png”></Property>
</File>
</Module>
</Elements>

For the page layouts, things are slightly more complex. Here, we need to specify the following:-

  • ‘ContentType’ – specifies whether the file is a page layout or master page. Use the value ‘$Resources:cmscore,contenttype_pagelayout_name;’ to specify SharePoint’s internal string which represents the page layout option.
  • ‘PublishingPreviewImage’ – path to URL accessible image file to be displayed when this layout is selected in the listbox when creating a page.
  • ‘PublishingAssociatedContentType’ – this is where we specify which content type the layout should be associated with. This means the layout will automatically have this binding and will be ready for use. Note that if this value is omitted, by default your layout will be associated with the basic ‘Page’ content type from the publishing feature. This means any custom columns you have added will not be available. The value for this property should be in form ‘;#<Content type name>;#<Content type ID;#>. So a real example would be ‘;#Welcome Page;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064DEA0F50FC8C147B0B6EA0636C4A7D4;#’.

Create a .cmd file and copy the code below in the cmd file and execute it.

@setlocal
@pushd.
@set PATH=C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN;%PATH% @cd %~dp0

stsadm.exe -o addsolution -filename MasterDeployment.wsp
stsadm.exe -o deploysolution MasterDeployment.wsp -allowgacdeployment -immediate
iisreset
@popd
@endlocal

Note: When you want to add the new deployed Page to your SP MasterPage and receive this error message:

An error occurred during the processing of . http://server//_catalogs/masterpage/RZB_Page_Layout.aspx(62): error CS0030: Cannot convert type ‘Microsoft.SharePoint.Publishing.WebControls.SummaryLinkFieldControl’ to ‘System.Web.UI.IAttributeAccessor’

Solution:  to fix it is to open the master page and you’ll see a big chunk of html that is commented out. Delete that chunk, and the master page will work properly again.

Other information:

http://www.sharepointblogs.com/michael/archive/2009/05/25/manage-webparts-of-page-layouts-through-a-feature-resolving-the-quot-alluserswebpart-quot-pain.aspx

http://www.wssdemo.com/Blog/archive/2008/10/27/creating-a-sharepoint-page-layout-to-play-video-content.aspx

Advertisements

One Response to “Deployment for a Custom SP PageLayout”

  1. Michael said

    Panvega, I wonder if you might be the one to resolve a problem that bothers me. It is related to page layout.
    I have a Site template that I want to use to create multiple sites from. I saved it into a template. When I create a new site based on my template, an error occurs, meaning that the default page of the new site has got no valid page layout. I can see in the pages library that the object indeed lacks a value in the page layout field.
    Is there a way to change this field to the correct value of “/websites/portal/_catalogs/masterpage/WelcomeLinks.aspx”?

    Your help is greatly appreciated.
    Michael

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: