PublishingWeb.SetAvailablePageLayouts method

Specifies PageLayout objects that are available for use in creating PublishingPage objects within this PublishingWeb object.

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

public void SetAvailablePageLayouts(
	PageLayout[] pageLayouts,
	bool resetAllSubsitesToInherit


Type: []

An array of PageLayout objects that are available for use in creating PublishingPage objects within this PublishingWeb object.

Type: System.Boolean

This Boolean parameter indicates whether the available PageLayout objects should be pushed down to all subsites.

After calling this method, the GetAvailablePageLayouts method returns this set PageLayout objects. The IsInheritingAvailablePageLayouts()and IsAllowingAllPageLayouts() properties are False.

To save changes after calling this method, call the Update method.


This operation is synchronous.

This example restricts the set of available page layouts used for creating pages in a publishing Web so that only page layouts associated with a specified content type are available.

Before using this example, verify that the associatedContentTypeId parameter is from a content type on the root Web site of the site.

using SPContentTypeId = Microsoft.SharePoint.SPContentTypeId;
using SPContentType = Microsoft.SharePoint.SPContentType;
using SPSite = Microsoft.SharePoint.SPSite;
using SPFile = Microsoft.SharePoint.SPFile;
using SPWeb = Microsoft.SharePoint.SPWeb;
using PublishingSite = Microsoft.SharePoint.Publishing.PublishingSite;
using PublishingWeb = Microsoft.SharePoint.Publishing.PublishingWeb;
using PageLayoutCollection = Microsoft.SharePoint.Publishing.PageLayoutCollection;
using PageLayout = Microsoft.SharePoint.Publishing.PageLayout;

namespace Microsoft.SDK.SharePointServer.Samples
    public static class PublishingWebCodeSamples
        public static void RestrictPageLayoutsByContentType(
PublishingWeb publishingWeb, 
SPContentTypeId associatedContentTypeId)
// Replace these variable values and input parameters with your own values.
bool excludeHiddenLayouts = true;
bool resetAllSubsitesToInherit = true;

// Validate the input parameters.
if (null == publishingWeb)
    throw new System.ArgumentNullException("publishingWeb");

SPSite site = publishingWeb.Web.Site;
PublishingSite publishingSite = new PublishingSite(site);

// Retrieve a collection of all page layouts in the site collection
// that match the content type.
SPContentType associatedContentType = publishingSite.ContentTypes[associatedContentTypeId];
if (null == associatedContentType)
    throw new System.ArgumentException(
        "The SPContentTypeId did not match an SPContentType in the SPSite.RootWeb",

PageLayoutCollection pageLayoutsByContentType = 
    publishingSite.GetPageLayouts(associatedContentType, excludeHiddenLayouts);

// Update the Web to use these page layouts when creating pages.


//  Verify the expected results. Note: This is not required. It demonstrates
//  the results of calling the SetAvailablePageLayouts method.

PageLayout[] availablePageLayouts = publishingWeb.GetAvailablePageLayouts();
foreach (PageLayout pageLayout in availablePageLayouts)
        pageLayout.AssociatedContentType.Id == associatedContentTypeId);