"I recently had the task of automating the replacement of all instances of one web part with another new web part throughout all site collections in SharePoint. There may have been thousands of instances of the web part in hundreds of thousands of site collections spread over more than 100 content databases, and all needed to be replaced with the new web part in exactly the same places where the original web parts were placed.
Here I will describe the approach used to replace the web part" [taken from Nick Hobbs - How to Replace all instances of a ShrePoint WebPart published on August 2010]
- Download the Web Part ID Generator from here.
- Go to the existing site collection and navigate to http://server/_layouts/newdwp.aspx
- Get the type name and the assembly name for the web part from that page.
- Copy and paste the assembly name and the type name in the webpart id generator and click on calculate id
- Copy the web part id.
- Go to the sql server and expand the content database.
- Paste this query and execute
select distinct d.SiteId,D.WebId, W.FullURL as WebURL, D.Id As DocumentId, D.DirName, D.LeafName, tp_ID As WebPartSK,w.Title as SiteTitle
FROM Docs D WITH (nolock)
INNER JOIN Webs W WITH (nolock) ON D.WebID = W.Id
INNER JOIN WebParts WP WITH (nolock) ON D.Id = WP.tp_PageUrlID
WHERE WP.tp_ListId Is Null AND WP.tp_Type Is Null AND WP.tp_Flags Is Null
AND WP.tp_BaseViewID Is Null AND WP.tp_DisplayName Is Null
AND WP.tp_WebPartTypeId=’b4bd2bdf-cf0c-ffce-ecb1-ae7c4882e17a’
8.The result window will show you the info about the pages which are used and the site title.
9.Once you make sure you are updating all the required pages.
10.Deploy the new web part on the system.
11.Navigate to http://server/_layouts/newdwp.aspx and get the
new type name and assembly.
12.Generate the Web part id using the ID generator tool.
Go back to sql and execute the below code
http://server/_layouts/newdwp.aspx and get the new type name and assembly.
12.Generate the Web part id using the ID generator tool.Go back to sql and execute the below code
DECLARE @OldWebPartTypeId uniqueidentifier
DECLARE @NewWebPartTypeId uniqueidentifier
SET @OldWebPartTypeId = ‘AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA’
SET @NewWebPartTypeId = ‘BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB’
UPDATE [WebParts]
SET [tp_WebPartTypeId] = @NewWebPartTypeId
WHERE [tp_WebPartTypeId] = @OldWebPartTypeId
13.Make sure you run the above steps 6 to 11 in all the content databases.
Original Content @ www.sharepointlovers.com