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?