SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a FeatureActivated event, I am trying to update the associated content type for a Page Layout. I am running in to issues though with the associated ASPX page not being checked out. Here's my code:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
    SPSite site = (SPSite)properties.Feature.Parent;
    if (PublishingSite.IsPublishingSite(site))
        PublishingSite pubSite = new PublishingSite(site);

        SPContentType ct = site.RootWeb.ContentTypes["Custom Page"];

        string layoutURL = site.ServerRelativeUrl + "_catalogs/masterpage/" + pageLayoutName;
        PageLayout layout = pubSite.PageLayouts[layoutURL];
        layout.AssociatedContentType = ct;

I've tried

PageLayout layout = pubSite.PageLayouts[layoutURL];
PublishingPage ppLayout = PublishingPage.GetPublishingPage(layout.ListItem);
layout.AssociatedContentType = ct;
ppLayout.CheckIn("Associated CT updated");

but this errors out with Error occurred in deployment step 'Activate Features': Invalid SPListItem. The SPListItem provided is not compatible with a Publishing Page.

Any ideas?

share|improve this question
up vote 1 down vote accepted

You need to do ListItem.CheckOut (for the list item represented by the page layout), rather than trying to check out the page object.

share|improve this answer
Thanks James! Right after I posted, another google search lead me to layout.ListItem.CheckOut();. I'll accept your answer in 6 minutes! – Tim Gabrhel Jun 14 '11 at 14:12
No worries, make sure you remember to Publish the item if you need to, too! – James Love Jun 14 '11 at 14:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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