Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you're looking for code, I've got something for you. If you'd like to find all Content Query web parts then you would call my code like this:</p> <pre><code>FindWebPart("http://server.com/", "Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart"); </code></pre> <p>Here's the code:</p> <pre><code>public static void FindWebPart(string siteCollectionUrl, string webPartName) { using (SPSite siteCollection = new SPSite(siteCollectionUrl)) { using (SPWeb rootSite = siteCollection.OpenWeb()) { FindWebPartHelper(rootSite, webPartName); } } } public static void FindWebPartHelper(SPWeb site, string webPartName) { // Search for web part in Pages document library SPList pagesList = null; try { pagesList = site.Lists["Pages"]; } catch (ArgumentException) { // List not found } if (null != pagesList) { SPListItemCollection pages = pagesList.Items; foreach (SPListItem page in pages) { SPFile file = page.File; using (SPLimitedWebPartManager mgr = file.GetLimitedWebPartManager(PersonalizationScope.Shared)) { try { SPLimitedWebPartCollection webparts = mgr.WebParts; foreach (System.Web.UI.WebControls.WebParts.WebPart wp in webparts) { // Here perform the webpart check // For instance you could identify the web part by // its class name if (webPartName == wp.GetType().ToString()) { // Found a match! Now do something... Console.WriteLine("Found web part!"); } } } finally { // Needs to be disposed mgr.Web.Dispose(); } } } } // Check sub sites SPWebCollection subSites = site.Webs; foreach (SPWeb subSite in subSites) { try { FindWebPartHelper(subSite, webPartName); } finally { // Don't forget to dispose! subSite.Dispose(); } } } </code></pre> <p>Ofcourse you can make little changes to this code. Currently it does a string comparison, but it's easy to do it in a more typed way. Have fun!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload