SharePoint 2010 – Setting DefaultPageLayout Programmatically
PublishingWeb has a DefaultPageLayout-property which contains information of the page layout to use when you select New Page from Site Actions. The property is readonly as you can see from msdn.
However – PublishingWeb has a method SetDefaultPageLayout which gives you the way to change the default page layout programmatically. Definition is found from msdn. A sample of how to use the programmatic approach is found from PublishingWeb’s SetAvailablePageLayouts definition. First you need to add the wanted page layout to your available page layouts collection before setting the default page layout with SetDefaultPageLayout.
My scenario was to staple a custom page layout with custom contenttype bound to it to one of the site template’s default page layout setting and the links provided above gave me the way to go although I was kind of lost when I first realized the DefaultPageLayout-property is readonly.
Might I just be doing it wrong but by doing it like this popped the question of the whole concept of default page layout being a little obscure. What was wrong with the dialog of selecting page layout from the available page layouts familiar from SharePoint 2007?
New page –dialog expects only the page name to be filled in. The page name then forms the file name (URL) of the page. What if you try to add a duplicate to the pages-library? Well, validation attached to the new page -control catches the event and doesn’t allow you to use the same page name again. So, if I’m not mistaken you would have to fill in a different page name to form a unique file name (URL) and change the title of the page which also is formed from the page name after the page is created if and when there are cases you need to have more than one page in your pages-library with the same title. My colleague Aapo Talvensaari has already designed a workaround to solve the problem described above. There would be no problem if /_layouts/createpage.aspx would be the URL of the new page –action. To me this finding seems like an indication that the new page –dialog as it is in SharePoint 2010 isn’t thought over thoroughly. One might even consider the dialog as being a design fault so take your time to read up on Aapo’s approach to the problem.
Popularity: 100% [?]