Saturday, September 20, 2014

Add publishing pages and web parts to the site programatically

Hi Guys

I had got the chance to work for adding the publishing pages to the given site through feature activation so that when the custom solution got deployed, the share point site is automatically associated with the custom web parts along with these publishing pages.

This is the sample code I wrote for my development purpose.
Please make sure that the publishing feature is activated on the site collection level and the site level.
In the code snippet, we need to use PublishingWeb class, which is component of Microsoft.SharePoint.Publishing.dll.
Make sure to add that dll and that namespace as well in your code to work as expected.




Here is the next code to add the specific web part to the existing page programatically.
Here we used the SPLimitedWebPartManager class to add the web part to the existing page.

No comments: