Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.