2

I'm trying to update the Layout of the default.aspx page in my SharePoint publishing site and although the Layout does get updated, the ContentType of the page does not. Anyone have any ideas?

Based on the example below, the assert is getting thrown all the time since the content types don't match.

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.publishing.publishingpage.contenttype.aspx

2 Answers 2

2

Sounds right to me, any given content type can use many page layouts some page layouts will even work for content types that decendants of the intended content type.

You should change the content type first then change the page layout.

-Gavin

3
  • For a publishing page, how do you change the content type? I thought changing the layout is supposed to automatically change the content type too. But it doesn't seem to be doing this on my SharePoint site. Oh, and just incase I wasn't clear, I'm doing this via the object model.
    – TehOne
    Commented Mar 6, 2012 at 6:31
  • You can change the content type of the page via the ContentTypeId field. Once that is set you can then change the PageLayout to one associated with the new content type.
    – GavinB
    Commented May 14, 2012 at 3:40
  • 1
    Just thought I'd come back an post an update on this. Just changing the page layout wasn't enough for me, I had to also set the ContentTypeId as @GavinB suggested. Here is a code snippet: page.Layout = newPageLayout; page.ListItem[SPBuiltInFieldId.ContentTypeId] = newPageLayout.AssociatedContentType.Id; page.Update();
    – TehOne
    Commented Aug 18, 2012 at 2:25
1

You may want to change the page layout to change the look, feel, and content of the page. In that case, you can have the different layout associated to same content type.

The ContentType property value is initialized when you create a PublishingPage; this value is based on the AssociatedContentType and cannot be modified.

Another option is to recreate the page using new layout\contentType

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.