Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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).

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

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();
    }
share|improve this answer
add comment

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
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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