Is it possible to analyse on which pages a webpart is in use?
I want to remove some webparts from my sharepoint server, but i don't know what's in use and what's not in use?
Is there a solution for it?
Im current using moss2007
Is it possible to analyse on which pages a webpart is in use?
I want to remove some webparts from my sharepoint server, but i don't know what's in use and what's not in use?
Is there a solution for it?
Im current using moss2007
Each web part added to a page is stored in the page itself. There's no central store that records where each web part is used.
This means unfortunately you need to iterate through every web part page in the site to retrieve this information. On each page you should then check the assembly names of the web parts. Add all the web parts you find to a list that is output once the application's completed.
The SPWeb object allows you to retrieve the web part manager for each page with SPWeb.GetLimitedWebPartManager(). Use the SPLimitedWebPartManager.WebParts property to retrieve a collection of web parts.
Alex's answer (iterating through sites -> pages > web parts) is good and the 'correct' way to do this but is fairly expensive on a very large site.
An alternative is a database query. All the usual caveats apply about accessing the database directly : do not change anything, could break at any time with service packs etc etc but assuming we are all big boys here :-
First you need to find out the WebPartTypeId of the web part your interested in
Next run this on ALL content databases.
SELECT DISTINCT D.SiteID, D.WebId, W.FullURL as WebURL, D.Id As DocumentId,
D.DirName, D.LeafName, tp_ID As WebPartSK
FROM dbo.Docs D WITH (nolock)
INNER JOIN dbo.Webs W WITH (nolock) ON D.WebID = W.Id
INNER JOIN dbo.WebParts WITH (nolock) WP 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_Version Is Null
AND WP.tp_WebPartTypeId='<your web parts id>'
You could do this the other way around (get a list of all WebPartTypeId's in use) but you can't get the assembly name from the WebPartTypeId hash so you would have to do some sort of lookup list of web parts > typeid's.
Another way to do this is use Gary Lapointe STSADM extensions,specifically enumPageWebParts
stsadm -o gl-enumpagewebparts -url "http://intranet/hr/pages/default.aspx" -verbose
It only outputs the web parts in use on a specific page but you could call this for each page on your site or even add a command to iterate over all pages in a site.