Tuesday, March 1, 2011

Feature to create page of a page layout type

In case you want to create a page of a certain page layout in your solution folder, Follow the below steps.

First create the page layout in your solution using feature. (Steps in another post)

Create a structure as below in your solution -

12 --
Template --
Features ---
Page123-----
Elements.xml
Feature.xml
TemplatePage.aspx


Elements.xml------------------------

Elements xmlns="http://schemas.microsoft.com/sharepoint/"
Module Name="PublishingHomePage" Url="$Resources:cmscore,List_Pages_UrlName;" Path=""
File Url="TemplatePage.aspx" Name="Welcome.aspx" Path="TemplatePage.aspx" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE"
Property Name="Title" Value="Online Services" /
Property Name="ContentType" Value="Article Page" /
Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/HomePageLayout.aspx, /sites/onlineservices/_catalogs/masterpage/HomePageLayout.aspx" /
/File
/Module
/Elements

Feature.xml----------------------------------

Feature Id="523E7D1F-052A-42e6-BD85-3ACFC82831EE"
Title="Page123"
Description="Home Page"
Version="1.0.0.0"
Scope="Site"
Hidden="True"
DefaultResourceFile="core"
xmlns="http://schemas.microsoft.com/sharepoint/"
ElementManifests
ElementManifest Location="Elements.xml"/
ElementFile Location="TemplatePage.aspx" /
/ElementManifests
/Feature

change the Feature id in your code.

TemplagePage.aspx--------------------- It is the normal templatepage in every site.

%@ Page Inherits="Microsoft.SharePoint.Publishing.TemplateRedirectionPage, Microsoft.SharePoint.Publishing,Version=12.0.0.0,Culture=neutral, PublicKeyToken=71e9bce111e9429c" %
%@ Reference VirtualPath="~TemplatePageUrl" %
%@ Reference VirtualPath="~masterurl/custom.master" %

Deploy this as a feature and your page is ready.

No comments:

Post a Comment