Publishing pages based on a SharePoint Article page layout programmatically

Glad I got some few minutes to update my blog after 2 months hence was in a busy schedule. J  Please refer the below code for you to create a Publishing page on Sharepoint 2010 based on a page layout which is available in your site.

PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
string pageName = “MyPageName.aspx”;
PageLayout[] pageLayouts = publishingWeb.GetAvailablePageLayouts();
PageLayout selectedLayout = null;
foreach (PageLayout pl in pageLayouts)
if (pl.Name == "MyPublishingPageLayout.aspx")
selectedLayout = pl;
PageLayout currPageLayout = selectedLayout;
PublishingPageCollection pages = publishingWeb.GetPublishingPages();
PublishingPage newPage = pages.Add(pageName,currPageLayout);
newPage.ListItem[FieldId.PublishingPageContent] = “Content of the page”;
newPage.CheckIn(“Comment for the checkin”);
newPage.ListItem.File.Publish("page published");
newPage.ListItem.File.Approve("page approved");

please refer the following links for more details:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: