0

I wonder if someone knows any C# script that will provide me all Site Features in a site collection as well as all Site collection features in a site collection.

I only required Activated features (GUID).

2

I think that when you use the Feature property in a SPSite or SpWeb you only get the active features on the "site collection"/site. So the code under will give you the active features on a site collection and all the sites in that site collection (write it to a file so you do not miss any because of the cmd buffer).

static void Main(string[] args)
    {
        using(SPSite site = new SPSite(args[0]))
        {
            foreach (SPFeature feature in site.Features)
            {
                Console.WriteLine("Site feature id {0}", feature.DefinitionId);
            }

            Console.ReadLine();

            foreach (SPWeb web in site.AllWebs)
            {
                try
                {
                    Console.WriteLine("Web title {0}", web.Title);

                    foreach (SPFeature feature in web.Features)
                    {
                        Console.WriteLine("Web feature id {0}", feature.DefinitionId);
                    }
                }
                finally
                {
                    if (web != null && web.Exists)
                        web.Dispose();
                }

            }
        }

        Console.ReadLine();
    }
1

This should get you started : http://www.c-sharpcorner.com/blogs/7698/get-the-list-of-activated-features-in-the-site-collection-an.aspx

However, it only shows the guid and not the feature name.

Alternatively you use these scripts:-

Features are activated for an SPSite:

Get-SPFeature -Site http://sitecollectionurl | Sort DisplayName | FT DisplayName,Id

List all activated web scoped features

Get-SPSite http://sitecollectionurl | Get-SPWeb -Limit ALL | %{ Get-SPFeature -Web $_ } | Sort DisplayName -Unique | FT DisplayName,Id
  • isn't that powershell script ? – Muhammad Raja Aug 6 '12 at 13:19
  • already went through that blog post, but I am looking for c# script not powershell, am afraid – Muhammad Raja Aug 6 '12 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.