Friday, August 7, 2009

Long time back I have posted an article on creating page layouts using SharePoint user interface and designer, now I am going to explain how to create page layouts using features


In this article, I am going to use WSPBuilder for building and deploying SharePoint solution, the main advantage of WSPBuilder is no need of creating manifest.xml , DDf file and cab file, the WSPBuilder will take care of creating all these things, so this will simplify our process
First, I am going to explain what are the entire things do we need for building SharePoint page layouts using features


Site Columns


A site column is a reusable column definition, or template, that you can assign to multiple lists across multiple SharePoint sites. These columns are directly mapped to table columns in SharePoint database


Her e I have created three columns Activity Name, Activity ID, Activity Image,


While creating site columns please make sure that each column have its own unique ID
You can get Unique ID using GUID tool


VS2008->Tools->Create GUID->Registry Format->Copy





Type="Text"
Name="ActivityName"
DisplayName="Activity Name"
StaticName="Activity Name"
Hidden="FALSE"
Required="FALSE"
Group="Activity Columns"
Sealed="FALSE" />
Type="Text"
Name="Activity ID"
DisplayName="Activity ID"
StaticName="Activity ID"
Hidden="FALSE"
Group="Activity Columns"
Required="FALSE"
Sealed="FALSE" />
Type="Image"
Name="Activity Image"
DisplayName="Activity Image"
StaticName="Activity Image"
Hidden="FALSE"
Group="Activity Columns"
Required="FALSE"
Sealed="FALSE" />



Site Content Type


Suppose if you want to manage your organization information in meaning full way across site collection then you can go for Site content types


A content type is a reusable collection of settings you want to apply to a certain category of content. Content types enable you to manage the metadata and behaviors of a document or item type in a centralized, reusable way


Here I have created activity content type that tells to the client that this content type belongs to only activity information


Every content type has FieldRef properties, these properties have a reference to site columns ID’s, that means this field(Site Column)and FieldRef both are pointing to same reference, so whenever we update site column’s that will automatically reflect in content type columns also
See below code all FieldRef Id’s are pointing to sit columns ID’s, if you want you can override some of the properties name, description etc…


Using below code we have created a content type, this is simple content type, it does not do anything so, we have to attach this to base page content type using Content type ID


The content type ID is the combination of base page ID and custom GUID which are separated by 00


Please refer MSDN link for more info on content type id http://msdn.microsoft.com/en-us/library/aa543822.aspx




Name="ActivityContentType"
Group="Demo"
Description="Demo Content Type"
Version="0">









Layout page


I suggest you guys create layout page using SharePoint designer and copy into your feature folder, so that you will not face any kind of problems and your work will be smooth


Below page is the which I have created using SharePoint designer


All the SharePoint controls of this layout page have a reference to site columns using Fieldname property, the Fieldname is the name of the site column


<%@ Page language="C#" Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" meta:webpartpageexpansion="full" meta:progid="SharePoint.WebPartPage.Document" %>
<%@ Register Tagprefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>














ProvisionedFiles.xml

I am using module element for deploying our page in master page gallery












Feature.xml

Title="PageLayoutDemo"
Description="Description for PageLayoutDemo"
Version="12.0.0.0"
Hidden="FALSE"
Scope="Site"
DefaultResourceFile="core"
xmlns="http://schemas.microsoft.com/sharepoint/">










So, we have created all necessary files which are required to create pagelayout, now we have to deploy all these files using features


I am using WSPBuilder for deploying all these files, I have posted an article on WSPBuilder please check it, if you need more info

0 comments:

Post a Comment