Sunday, March 13, 2016

Create page in SharePoint Programatically C#


Create page in SharePoint Programatically

 // web = SPWeb
SPSecurity.RunWithElevatedPrivileges(delegate()
            {               
                        PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);
                        string pageName = "CustomSPPage.aspx";

                        PageLayout[] pageLayouts = publishingWeb.GetAvailablePageLayouts();
                        PageLayout currPageLayout = pageLayouts[0];
                        PublishingPageCollection pages = publishingWeb.GetPublishingPages();

                        PublishingPage newPge = pages.Add(pageName, currPageLayout);

                        newPge.ListItem[FieldId.PublishingPageContent] = "my Test";

                        newPge.ListItem.Update();
                        newPge.Update();
                        newPge.CheckIn("all is well");                 

            });

No comments:

Post a Comment