Development Blog, SharePoint
Deploying Page Layouts to SharePoint 2010 through Visual Studio – Publish and Check-in
When deploying a branding solution through Visual Studio, you might notice that your Page Layouts will not be published, and could be ghosted as well. If you’re having a ghosting issue, follow this article. This post should be enough if all you want to do is deploy and publish a page layout.
The two things to note here, are that the master page gallery (where your page layouts and masterpages live) is actually a list. To manipulate the files in this gallery, you have to open it with SPList, which will open up all kinds of magical options, allowing you to check in and approve your files.
In your feature’s event receiver, add the following code:
public override void FeatureActivated(SPFeatureReceiverProperties properties) { using (SPSite siteCollection = (SPSite)properties.Feature.Parent) { if (siteCollection != null) { SPWeb topLevelSite = siteCollection.RootWeb; SPList masterPageGallery = topLevelSite.GetCatalog(SPListTemplateType.MasterPageCatalog); foreach (SPListItem li in masterPageGallery.Items) { if (li.File.Name.ToString() == "PageLayoutFileName1.aspx") { if (!li.HasPublishedVersion) { li.File.CheckIn("Automatically checked in by StephanRocks' feature", SPCheckinType.MajorCheckIn); li.File.Update(); li.File.Approve("Automatically approved by StephanRocks' feature"); li.File.Update(); } } if (li.File.Name.ToString() == "PageLayoutFileName2.aspx") { if (!li.HasPublishedVersion) { li.File.CheckIn("Automatically checked in by StephanRocks' feature", SPCheckinType.MajorCheckIn); li.File.Update(); li.File.Approve("Automatically approved by StephanRocks' feature"); li.File.Update(); } } } } } }
About Author
Comments are closed