PageLayout Constructor

Uses the SPListItem class to construct a PageLayout list item object in a document library.

Namespace:  Microsoft.SharePoint.Publishing
Assembly:  Microsoft.SharePoint.Publishing (in Microsoft.SharePoint.Publishing.dll)

public PageLayout(
	SPListItem listItem


Type: Microsoft.SharePoint.SPListItem
The SPListItem object that is constructed.


The listItem is a null reference (Nothing in Visual Basic), which is invalid.

Use this method to instantiate a PageLayout instance that wraps an SPListItem object that you have already retrieved. The SPListItem should be an item in the Master Page Gallery of the site collection.

The listItem must be an SPListItem instance and cannot be a null reference (Nothing in Visual Basic).

Before compiling and running this sample, verify that the SPListItem object is a list item for a page layout that resides in the Master Page Gallery on the root Web site.

This sample assumes that the Master Page Gallery that contains the SPListItem object requires content approval.


using PageLayout = Microsoft.SharePoint.Publishing.PageLayout;
using SPListItem = Microsoft.SharePoint.SPListItem;
using SPFile = Microsoft.SharePoint.SPFile;

namespace Microsoft.SDK.SharePointServer.Samples
    public static class PageLayoutCodeSamples
        // This method sets some properties on a PageLayout object,
        // saves the new values, and publishes the PageLayout.
        public static void SetPageLayoutPropertiesAndApprove(SPListItem layoutListItem)
            // TODO: Replace these variable values and input
            // parameters with your own values.
            // New PageLayout.Title value
            string newTitle = "your Title";
            // New PageLayout.Description value
            string newDescription = "your Description";
            // The comment to set when the layout is checked in,
            // published, and approved.
            string checkInComment = "your comments";
            // Validate the input parameters.
            if (null == layoutListItem)
                throw new System.ArgumentNullException("layoutListItem");

            // Get the PageLayout wrapper for the SPListItem
            // that is passed.
            PageLayout pageLayout = new PageLayout(layoutListItem);

            // Check out the PageLayout if it is not checked out yet.
            if (pageLayout.ListItem.File.CheckOutStatus == SPFile.SPCheckOutStatus.None)

            // Set and save some properties on the PageLayout.
            pageLayout.Title = newTitle;
            pageLayout.Description = newDescription;

            // Publish the PageLayout and approve it so that the
            // updated values are available on the published Web site.
            SPFile layoutFile = pageLayout.ListItem.File;


Community Additions