I would like to automate creation of a subsite and of a publishing site. Is it possible to create a publishing site and also dynamically add webparts to it e.g create also a document library on the fly and then add it to particular webpart zone

Thanks in advance

PublishingPageInformation publishingPageInfo = new PublishingPageInformation();
publishingPageInfo.Name = pageFileName // Set file name here;
publishingPageInfo.PageLayoutListItem = layout // Url of the page layout inside master page gallery;
// Adding new page to web.
PublishingPage publishingPage =pubWeb.AddPublishingPage(publishingPageInfo);
publishingPage.ListItem["Title"] = pageTitle; //title of the page
pageURL = publishingPage.ListItem["FileRef"].ToString(); // this will give you the URL of the page added

Don't forget to include using Microsoft.SharePoint.Client.Publishing; reference.

I hope this helps you to solve the problem.

  • Thanks users1100. About adding webparts dynamically to the page? – naijacoder Dec 7 '17 at 11:49

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.