This is one of the most recurrent tasks... dealing with pages list.
You created your pages list content types, associated page layouts to those content types, and customers want to use only those content type and page layouts or simply.
Ok, let's assume you have Example 04 deployed (if it's your first time on this blog, download VLibs here), this is what you see in Pages list.
The key to accomplish this task is divide-et-impera, so what about the new page menu?
Work on this property
The second step is to make a selection of page layouts available, the method is:
And this is what we will get
If you need the code, as usual this is the link. Go get it! and have a look at Example 06 ;) .
You created your pages list content types, associated page layouts to those content types, and customers want to use only those content type and page layouts or simply.
Ok, let's assume you have Example 04 deployed (if it's your first time on this blog, download VLibs here), this is what you see in Pages list.
The key to accomplish this task is divide-et-impera, so what about the new page menu?
Work on this property
IList<SPContentType> contentTypeInstances2Show = ... pagesList.RootFolder.UniqueContentTypeOrder = contentTypeInstances2Show; pagesList.RootFolder.Update();Assigning a SPContentType list to UniqueContentTypeOrder, we give the order of the content type available for creating, and we can also exclude some of them from the menu.
The second step is to make a selection of page layouts available, the method is:
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web); PageLayout[] pageLayouts = publishingWeb.GetAvailablePageLayouts(); PageLayout[] pageLayouts2Show = ... publishingWeb.SetAvailablePageLayouts(pageLayouts2Show .ToArray(), false);So you have first to select content type related page layouts, just querying the publish website.
And this is what we will get
New document menu |
Available page layouts |
If you need the code, as usual this is the link. Go get it! and have a look at Example 06 ;) .