Thursday, August 19, 2010

How to get all available page layouts which can be used to create and page

There was a task in which i had to check what all page layouts are available for a current site which can be used to create a new page. So here is the solution

PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);

PageLayout[] pageLayouts = pubWeb.GetAvailablePageLayouts();

PageLayout pageLayout = pageLayouts.Where(p => p.Title.Trim() == item["LayoutName"].ToString().Trim()).FirstOrDefault();

if (pageLayout == null)
.......

Cheers....

No comments: