Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>By way of an alternative, if you want to test web part pages including the default page on collaboration sites, you can use the following code snippet which uses the Files property of the SPWeb object:</p> <pre><code>private static void FindWebPart(string siteUrl, string webPartName) { using (var site = new SPSite(siteUrl)) { foreach (SPWeb web in site.AllWebs) { foreach (var file in web.Files.Cast&lt;SPFile&gt;().Where(file =&gt; file.Name.EndsWith("aspx"))) { FindWebPartOnPage(webPartName, file); } var pagesTemplateType = (SPListTemplateType)Enum.Parse(typeof(SPListTemplateType), "850"); foreach (var documentLibrary in web.Lists.Cast&lt;SPList&gt;().Where(list =&gt; list.BaseTemplate == pagesTemplateType || (list.BaseTemplate == SPListTemplateType.DocumentLibrary &amp;&amp; list.Title.Contains("Pages")))) { foreach (var file in documentLibrary.Items.Cast&lt;SPListItem&gt;().Where(item =&gt; item.File.Name.EndsWith("aspx")).Select(item =&gt; item.File)) { FindWebPartOnPage(webPartName, file); } } web.Dispose(); } } } private static void FindWebPartOnPage(string webPartName, SPFile file) { using (var webPartManager = file.GetLimitedWebPartManager(PersonalizationScope.Shared)) { if (webPartManager.WebParts.Cast&lt;WebPart&gt;().Any(webPart =&gt; webPart.GetType().Name == webPartName)) { Console.WriteLine(file.ServerRelativeUrl); } webPartManager.Web.Dispose(); } } </code></pre> <p>Note: the Pages library created by the Publishing feature does not have a BaseTemplate value of SPListTemplateType.DocumentLibrary; instead it is represented by a "hidden" value of 850.</p> <p>This is called a similar manner to LeonZandman's answer, however only the class name is used to supply a match:</p> <pre><code>FindWebPart("http://yoursite.com/", "MyWebPart"); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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