C# – how to add a WebPart to all pages in a SharePoint site

asp.netcnetsharepoint-2007visual-studio-2008

I am using SharePiont Server 2007 Enterprise with Windows Server 2008 Enterprise, and I am using publishing portal template. I am developing using VSTS 2008 + C# + .Net 3.5. I want to know how to add a WebPart to all pages of a SharePoint Site? Any reference samples?

I want to use this WebPart to display some common information (but the information may change dynamically, and it is why I choose a WebPart) on all pages.

Best Answer

There are two ways to do this depending on your situation.

If the sites exist already, you need to iterate over the sites, adding the web part:

http://blogs.msdn.com/tconte/archive/2007/01/18/programmatically-adding-web-parts-to-a-page.aspx

If the sites do not exist then you can add the web part to the site template:

How to add a web part page to a site definition?

Related Topic