in SharePoint, SharePoint 2007

Set Available PageLayouts for your Site

Below is a code snippet for setting available page layouts for your site:


List<String> strPageLayoutsToPersist =

        new List<string> { "Home Page", 

                           "General Detail Page", 

                           "Email Me Page", 

                           "Category Page" 


using (SPWeb spWeb = spSite.RootWeb)


        PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(spWeb);


        // Get avaialble page layouts for our content types

        PageLayout[] myPageLayouts = pubWeb.GetAvailablePageLayouts().Cast<PageLayout>()

            .Where(p => strPageLayoutsToPersist.Contains(p.AssociatedContentType.Name))



        // Set the available page layouts to our content type

        pubWeb.SetAvailablePageLayouts(myPageLayouts, false);


        // Update the web




This will hide every page layouts except those you specify in the strPageLayoutsToPersist

Write a Comment


Time limit is exhausted. Please reload the CAPTCHA.