How can I save or check in my Home.aspx pagelayout?

Whenever I try to save or check in my Home.aspx pagelayout welcome page I get the following error.

Invalid SPListItem. The SPListItem provided is not compatible with a Publishing Page.

And this:

Microsoft.SharePoint.Publishing.PublishingPage.GetPublishingPage(SPListItem sourceListItem) +303
   Microsoft.SharePoint.Publishing.Internal.WebControls.PublishingPageStateControl.RaisePostBackEventForPageRouting(String eventArgument, SPRibbonCommandHandler control, RaisePostBackEventDelegate raisePostBackEventDelegate) +110
   Microsoft.SharePoint.Publishing.Internal.WebControls.PublishingPageSaveAndStopEditHandler.RaisePostBackEvent(String eventArgument) +134
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981

I have created home.aspx as a new pagelayout as a welcome page.


It would help to see your code, but you can try this one.
I think this would do the trick.

using (SPSite site = new SPSite("http://myservier"))
    using (SPWeb web = site.OpenWeb())
        PublishingSite pSite = new PublishingSite(site);
        SPContentType ctype = pSite.ContentTypes["MyWelcomePage"];
        PageLayoutCollection pageLayouts = pSite.GetPageLayouts(ctype, true);
        PageLayout pageLayout = pageLayouts["/_catalogs/masterpage/PageLayout.aspx"];
        PublishingWeb pWeb = PublishingWeb.GetPublishingWeb(web);
        PublishingPageCollection pPages = pWeb.GetPublishingPages();
        PublishingPage pPage = pPages.Add("home.aspx", pageLayout);
        SPListItem newpage = pPage.ListItem;
        newpage["Title"] = "Page added programmatically";

        newpage.File.CheckIn("CheckIn programmatically");
        newpage.File.Publish("Publish programmatically");

Good luck.

| improve this answer | |
  • Please forgive my stupidity - where do I need to place this code? – Morten Hagh Jan 10 '13 at 14:50
  • Did you create your home.aspx page programmatically? or by using the SharePoint UI? – Alex Choroshin Jan 10 '13 at 14:56
  • I created it with Sharepoint Designer – Morten Hagh Jan 10 '13 at 14:58
  • Try to deactivate and reactivate the SharePoint Server Publishing site feature – Alex Choroshin Jan 10 '13 at 15:02
  • I have tried that - it didn't seem to work ... – Morten Hagh Jan 10 '13 at 17:02

From your comments, it seems you created the Page Layout using SharePoint Designer.

Can you try to re-create the Page Layout using SharePoint Design Manager?

Tutorial: How to: Create a page layout in SharePoint 2013

| improve this answer | |
  • 2
    Water, welcome to SharePoint StackExchange. One of the standards we try to keep is adding at least an over-view of the steps in an answer rather than just offering a link as frequently blog posts and sites move or get deleted. That might not be the case with an MSDN page, but at least and over-view helps improve the quality of our community. – Robert Kaucher Feb 10 '14 at 3:33

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.