3

Is it possible to update the available page layouts of a web using CSOM? In the interface you can change them by going to the site setting and then to page layout and site template settings, but I didn't find an option yet to do it in code.

EDIT

It looks like I'm able to change the pagelayouts by changing the "__PageLayouts" property of the web. The current value looks like this (I manually did the formatting to make it a bit more readable):

<pagelayouts>
  <layout guid="a62d560d-d34d-4154-80b5-7163e91cd62e" url="_catalogs/masterpage/ContactPage.aspx" />
  <layout guid="efc0944d-4992-4c14-a0d4-5c1632bb04b5" url="_catalogs/masterpage/HowDoI.aspx" />
</pagelayouts>

The thing is, I don't got a clue where these guids are coming from and if I'm able to retrieve them using CSOM

2
  • Each unique page and list should have it's own unique GUID.
    – Brandon C.
    Commented Jun 17, 2014 at 13:01
  • Yes, but is there a way to retrieve that unique GUID?
    – Marlou
    Commented Jun 18, 2014 at 13:10

2 Answers 2

2

Having reflected the assembly that provides the SetAvailablePageLayouts, I can confirm that all it is doing is setting the "__PageLayouts" web property (and pushing this update to child webs). As such using CSOM to set the property should be sufficient. I assume that the GUID is the UniqueId of the page layout in _catalogs/masterpage gallery.

1

In Microsoft'S API, there is a function called SetAvailablePageLayouts() that let'S you, like it says, set the available page layouts for a PublishingPage object. In C#, the general function definition is

public void SetAvailablePageLayouts(
PageLayout[] pageLayouts,
bool resetAllSubsitesToInherit
)

Just create a new publishing page object by using GetPublishingWeb($your_SPWeb_var), and then call this function, setting the pageLayouts array with the list of layouts you want to allow.

EDIT: Note that this is for the server-side API, which you may not want to use. I will search for a similar use for client-side, and update my answer accordingly. For now, wait for more appropriate answers.

2
  • 2
    Is this method really available in the client side API? Your link is refering to the server side API Commented Jun 17, 2014 at 11:46
  • 1
    Ahh, misunderstood the question, you are absolutely right. I will append the question to reflect this, and continue searching the client-side API. Thank you!
    – Brandon C.
    Commented Jun 17, 2014 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.