Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Monday, November 28, 2011

Create publishing pages sharepoint 2010 programmatically

Create publishing pages sharepoint 2010 programmatically

Below is an example of Adding a New Publishing Page to the SharePoint 2010 Site Pages Library

PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);

string pageName = “MyCustomPage.aspx”;

PageLayout[] pageLayouts = publishingWeb.GetAvailablePageLayouts();

PageLayout currPageLayout = pageLayouts[0];

PublishingPageCollection pages = publishingWeb.GetPublishingPages();

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

newPage.ListItem[FieldId.PublishingPageContent] = “This is my content”;

newPage.ListItem.Update();

newPage.Update();

newPage.CheckIn(“This is just a comment”);

In the code above a PageLayout instance with index 0 is selected from all the available page layouts. By using the PageLayout instance, a new page of type PublishingPage is added to the site pages library. Afterward, the content of a field, identified by FieldId.PublishingPageContent, is set to a HTML text value, followed by an update and check-in.

No comments:

Post a Comment