11 January 2008

Programmatically Adding Web Parts to Pages

Today I was working to make modifications to a site that was being provisioned via automation code. The code creates a batch of sites and then uploads various data to the site for review by members of the site. The goal of the automation is to insure a consistent user experience with web parts to containing lists and libararies in the same place. However, I couldn't see exactly where this would be accomplished in the object model of SharePoint, so I pulled up Google and began searching. I came across this post by Thomas Conté that was very helpful.

2 comments:

Anonymous said...

To add/remove web parts programmatically refer following post:

http://www.etechplanet.com/post/2009/03/18/AddingRemoving-web-part-programmatically-in-SharePoint-website-using-C-Code.aspx

Chris said...

Avi, I just noticed today that the components being used are obsolete under the SharePoint 2007 OM.

Instead of using SPWebPartCollection you should use Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager and your project will need a reference to System.Web.