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 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_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.
And in case anyone is looking for the same query for SharePoint 2013. Here it is. The view has been removed in 2013 and the table name that has the same fields is dbo.AllWebParts.
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.AllWebParts 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_Version Is Null
AND WP.tp_WebPartTypeId='<your web parts id>'
I've had no success generating the web part type id by any method, I simply get no results when I execute the query. This was because the id was never correct.
To get around this issue, I created a new page and inserted an instance of the web part I was interested in. I then query by LeafName, giving it the page I'd created (Best to make it unique!). This returned a single result and I could then use the tp_WebPartTypeId it returned to query the entire content database.
So if you're having trouble generating the id, try this approach instead.
© 2022 - 2024 — McMap. All rights reserved.