Tag Archives: Object Model

List all Web features with Object Model

Just a little C# sniplet which lists all feature IDs of a SharePoint web:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint;
namespace SiteCollections
{
    class Program
    {
        static void Main(string[] args)
        {
            SPFarm farm = SPFarm.Local;
            SPWebService service = farm.Services.GetValue<SPWebService>(“”);
            foreach (SPWebApplication webapp in service.WebApplications)
            {
                Console.WriteLine(“Web Application: ” + webapp.Name);
                foreach (SPSite site in webapp.Sites)
                {
                    Console.WriteLine(” Site Collection URL: ” + site.Url);
                    foreach (SPWeb web in site.AllWebs)
                    {
                        Console.WriteLine(“  Web URL: ” + web.Url);
                        foreach (SPFeature feature in web.Features)
                        {
                            Console.WriteLine(“    Feature ID: ” + feature.DefinitionId);
                        }
                    }
                }
                Console.WriteLine(“n”);
            }
        }
    }
}