Il seguente codice C# permette di cercare in tutte le site collection (SPSite) e siti (SPWeb) di una WebApplication (SPWebApplication) SharePoint 2007 / 2010 se esiste l'id della feature passato con scope Site o Web.

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace ElencoFeatures
{
  class Program
  {
    private static System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(1033);

    static void Main(string[] args)
    {
      try
      {

        string url = args[0]; //url
        Guid featureId = Guid.Empty;
        if (args.Length > 1)
        {
          string g = args[1]; //id to find
          featureId = new Guid(g);
        }

        using (SPSite site1 = new SPSite(url))
        {
          Console.WriteLine("User:" + site1.RootWeb.CurrentUser);
          site1.CatchAccessDeniedException = false;
          SPWebApplication wApp = site1.WebApplication;

          foreach (SPSite site in wApp.Sites)
          {
            // feature scope site collection (SPSite)
            ShowFeatures(site.Features, featureId, site.ServerRelativeUrl);

            //feature scope web (SPWeb)
            foreach (SPWeb web in site.AllWebs)
            {
              ShowFeatures(web.Features, featureId, web.ServerRelativeUrl);
              web.Dispose();
            }
          }
        }
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex);
      }
    }

    private static void ShowFeatures(SPFeatureCollection features, Guid featureId, string url)
    {
      foreach (SPFeature f in features)
      {
        if (featureId == Guid.Empty || f.DefinitionId == featureId)
        {
          Console.WriteLine(string.Format("{0};{1};{2};{3};{4}"
          , url
          , f.Definition.Scope, f.DefinitionId
          , f.Definition.DisplayName, f.Definition.GetTitle(ci)));
        }
      }
    }
  }
}
da richiamare con
CercaFeature.exe http://sharepoint2007 75a0fea7-fe9d-4119-9615-2c2ef22d6fdb
per elencare i siti dove è usata una specifica feature id, oppure
CercaFeature.exe http://sharepoint2007 
per elencare tutti i siti con tutte le feature.

Da un output simile al seguente:

Text

/;Site;a392da98-270b-4e85-9769-04c0fde267aa;PublishingPrerequisites;Publishing Prerequisites
/;Site;f6924d36-2fa8-4f0b-b16d-06b7250180fa;PublishingSite;Office SharePoint Server Publishing Infrastructure
...
/;Web;00bfea71-c796-4402-9f2f-0eb9a6e71b18;WebPageLibrary;Wiki Page Library
/;Web;00bfea71-5932-4f9c-ad71-1557e5751100;IssuesList;Issues Lists
...
/Bacheca;Web;00bfea71-c796-4402-9f2f-0eb9a6e71b18;WebPageLibrary;Wiki Page Library
/Bacheca;Web;065c78be-5231-477e-a972-14177cc5b3c7;BizAppsListTemplates;SharePoint Portal Server Status Indicator List template
...

Utile in fase di migrazione da SharePoint 2007 a 2010 per identificare un feature id segnalato nei log.
Tags:
C#236 SharePoint498 SharePoint 2007218 SharePoint 2010224
Potrebbe interessarti anche: