2

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;
        layout.Update();
    }
}

I've tried

PageLayout layout = pubSite.PageLayouts[layoutURL];
PublishingPage ppLayout = PublishingPage.GetPublishingPage(layout.ListItem);
ppLayout.CheckOut();
layout.AssociatedContentType = ct;
layout.Update();
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?

1

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

2
  • Thanks James! Right after I posted, another google search lead me to layout.ListItem.CheckOut();. I'll accept your answer in 6 minutes! 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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