1

I need to set the page layout of my custom sitepage to my own custom page layout. How to modify the page layout of a Sitepage created via Visual Studio ?

EDIT

My current sitepage markup is as follows:

<%-- SPG:

This HTML file has been associated with a SharePoint Page Layout (.aspx file) carrying the same name.  While the files remain associated, you will not be allowed to edit the .aspx file, and any rename, move, or deletion operations will be reciprocated.

To build the page layout directly from this HTML file, simply fill in the contents of content placeholders.  Use the Snippet Generator at https://esiadsspdplot2:4446/_layouts/15/ComponentHome.aspx?Url=https%3A%2F%2Fesiadsspdplot2%3A4446%2F%5Fcatalogs%2Fmasterpage%2FSPDPContextsPageLayout%2Easpx to create and customize additional content placeholders and other useful SharePoint entities, then copy and paste them as HTML snippets into your HTML code.   All updates to this file within content placeholders will automatically sync to the associated page layout.

 --%>
<%@Page language="C#" Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>
<%@Register TagPrefix="PageFieldFieldValue" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>
<%@Register TagPrefix="Publishing" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>
<%@Register TagPrefix="PageFieldTextField" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>
<%@Register TagPrefix="PageFieldRichImageField" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>
<%@Register TagPrefix="PageFieldRichHtmlField" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>
<%@Register TagPrefix="PageFieldSummaryLinkFieldControl" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>
<%@Register TagPrefix="PageFieldDateTimeField" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>
<%@Register TagPrefix="PageFieldTaxonomyFieldControl" Namespace="Microsoft.SharePoint.Taxonomy" Assembly="Microsoft.SharePoint.Taxonomy, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>
<asp:Content runat="server" ContentPlaceHolderID="PlaceHolderPageTitle">


            <PageFieldFieldValue:FieldValue FieldName="fa564e0f-0c70-4ab9-b863-0177e6ddd247" runat="server">
            </PageFieldFieldValue:FieldValue>

        </asp:Content><asp:Content runat="server" ContentPlaceHolderID="PlaceHolderMain">
            <div>



                <Publishing:EditModePanel runat="server" CssClass="edit-mode-panel">
                    <PageFieldTextField:TextField FieldName="fa564e0f-0c70-4ab9-b863-0177e6ddd247" runat="server">
                    </PageFieldTextField:TextField>
                </Publishing:EditModePanel>

            </div>
            <div>


                <PageFieldRichImageField:RichImageField FieldName="3de94b06-4120-41a5-b907-88773e493458" runat="server">

                </PageFieldRichImageField:RichImageField>

            </div>
            <div>


                <PageFieldRichHtmlField:RichHtmlField FieldName="f55c4d88-1f2e-4ad9-aaa8-819af4ee7ee8" runat="server">

                </PageFieldRichHtmlField:RichHtmlField>

            </div>
            <div>


                <PageFieldSummaryLinkFieldControl:SummaryLinkFieldControl FieldName="b3525efe-59b5-4f0f-b1e4-6e26cb6ef6aa" runat="server">

                </PageFieldSummaryLinkFieldControl:SummaryLinkFieldControl>

            </div>
            <div>


                <PageFieldTextField:TextField FieldName="d3429cc9-adc4-439b-84a8-5679070f84cb" runat="server">

                </PageFieldTextField:TextField>

            </div>
            <div>


                <PageFieldDateTimeField:DateTimeField FieldName="71316cea-40a0-49f3-8659-f0cefdbdbd4f" runat="server">

                </PageFieldDateTimeField:DateTimeField>

            </div>
            <div>


                <PageFieldRichHtmlField:RichHtmlField FieldName="66f500e9-7955-49ab-abb1-663621727d10" runat="server">

                </PageFieldRichHtmlField:RichHtmlField>

            </div>
            <div>


                <PageFieldRichHtmlField:RichHtmlField FieldName="817b4284-4340-42f2-a271-3b32e3a8eaf4" runat="server">

                </PageFieldRichHtmlField:RichHtmlField>

            </div>
            <div>


                <PageFieldTaxonomyFieldControl:TaxonomyFieldControl FieldName="72ec093c-2db3-4d0e-b0cb-6f9ebeb69d5e" runat="server">

                </PageFieldTaxonomyFieldControl:TaxonomyFieldControl>

            </div>
        </asp:Content><asp:Content runat="server" ContentPlaceHolderID="PlaceHolderFormDigest">
            <SharePoint:FormDigest runat="server" />
        </asp:Content><asp:Content runat="server" ContentPlaceHolderID="PlaceHolderAdditionalPageHead">



            <Publishing:EditModePanel runat="server" id="editmodestyles">
                <SharePoint:CssRegistration name="&lt;% $SPUrl:~sitecollection/Style Library/~language/Themable/Core Styles/editmode15.css %&gt;" After="&lt;% $SPUrl:~sitecollection/Style Library/~language/Themable/Core Styles/pagelayouts15.css %&gt;" runat="server">
                </SharePoint:CssRegistration>
            </Publishing:EditModePanel>

        </asp:Content><asp:Content runat="server" ContentPlaceHolderID="PlaceHolderSiteName">
            <SharePoint:SPLinkButton runat="server" NavigateUrl="~site/" id="onetidProjectPropertyTitle1">
            <SharePoint:ProjectProperty Property="Title" runat="server" />

            </SharePoint:SPLinkButton>
        </asp:Content><asp:Content runat="server" ContentPlaceHolderID="PlaceHolderSearchArea">
            <div id="searchInputBox">
                <SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox" />

            </div>
        </asp:Content><asp:Content runat="server" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea">
            <SharePoint:SPTitleBreadcrumb runat="server" RenderCurrentNodeAsLink="true" SiteMapProvider="SPContentMapProvider" WelcomePageUsesWebTitle="false">
            <PATHSEPARATORTEMPLATE>
            <SharePoint:ClusteredDirectionalSeparatorArrow runat="server" />
            </PATHSEPARATORTEMPLATE>
            </SharePoint:SPTitleBreadcrumb>


            <PageFieldFieldValue:FieldValue FieldName="fa564e0f-0c70-4ab9-b863-0177e6ddd247" runat="server">
            </PageFieldFieldValue:FieldValue>

        </asp:Content>
2

Anish,

When creating a page you can specify the Page Layout, we use this function to create new Pages with specified Page Layout:

    /// <summary>
    /// Instantiates a publishing page in the Pages list from a given page layout
    /// </summary>
    /// <param name="PageName">The page name including the .aspx</param>
    /// <param name="PageTitle">The page title</param>
    /// <param name="PageLayoutName">The page layout name including .aspx</param>
    /// <param name="pubWeb">an instance from the current publishing web</param>
    public PublishingPage InstantiatePublishingPage(string PageName, string PageTitle, string PageLayoutName, PublishingWeb pubWeb)
    {
        PageLayout[] allLayouts = pubWeb.GetAvailablePageLayouts();
        PageLayout objPageLayout = allLayouts.FirstOrDefault(a => a.Name == PageLayoutName);
        PublishingPage objPage = pubWeb.AddPublishingPage(PageName, objPageLayout);
        objPage.Title = PageTitle;
        objPage.Update();
        objPage.CheckIn("");
        return objPage;
    }

You can call the function like this:

InstantiatePublishingPage("PageName.aspx", "Page Title", "PageLayout-Name.aspx", publishingWeb);

You can also change the Page Layout of a page (by getting the existing page)

PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web); //SPWeb web
PageLayout pageLayout = null;
foreach (PageLayout p in publishingWeb.GetAvailablePageLayouts())
{
   if (p.Name.Equals("PageLayout-Name.aspx", StringComparison.InvariantCultureIgnoreCase))
    {
       pageLayout = p;
       break;
    }
}

PublishingPage page = publishingWeb.GetPublishingPage(web.ServerRelativeUrl + "/Pages/PageName.aspx");
page.CheckOut();
page.Layout = pageLayout;
page.Update();
page.CheckIn("");
9
  • Thanks for your reply. I need to do it without using any code. Is there any way to specify the pagelayout in the sitepage markup ?
    – Anish V
    Feb 24 '14 at 8:09
  • Can you please provide the Sitepage markup (edit the question and provide the xml) Feb 24 '14 at 8:11
  • I have created this current layout using design manager. Will update the question with that now.
    – Anish V
    Feb 24 '14 at 8:13
  • That isn't a page, its a Page Layout.. you can create new pages based on this Page Layout by going to Site Settings -> Create New Page (give page name).. Than in Ribbon -> Under Page -> Page Layout -> Choose your Page Layout here Feb 24 '14 at 8:56
  • Page layout is disabled for me. Full permissions are there. .I think I have removed the current layouts from 'Page Layouts and site templates'. Now, I'm not able to take that option.. Getting error. Is there any other way to add a page layout to site collection using SPD or powershell ?
    – Anish V
    Feb 24 '14 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.