Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharepoint find where webpart is in use

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

like image 244
Active_t Avatar asked Sep 30 '09 14:09

Active_t


2 Answers

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.

like image 79
Alex Angas Avatar answered Oct 21 '22 15:10

Alex Angas


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.

like image 35
Ryan Avatar answered Oct 21 '22 15:10

Ryan