Retrieve Site Features in SharePoint

Leave a Comment
Hi All,

In a following example we will see how to retrieve features (default SharePoint features and our Custom written features) which are activated at web level.

Please find the below console example , which will show Feature Id along with Feature Name.


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;
using System.Xml;
using System.IO;

namespace PO_TestApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            Program obj = new Program();
            obj.GetWebFeatures();
            Console.ReadLine();
        }

        public void GetWebFeatures()
        {
            try
            {
                using (SPSite oSite = new SPSite("SiteUrl"))
                {
                    using (SPWeb oWeb = oSite.OpenWeb())
                    {
                        SPFeatureCollection _featureColl=oWeb.Features;
                        foreach(SPFeature _feature in _featureColl)
                        {
                            Console.WriteLine("*********START*********");
                            Console.WriteLine("Feature ID: " + _feature.DefinitionId);
                            Console.WriteLine("Feature Name: "+_feature.Definition.DisplayName);
                            Console.WriteLine("********* END ********");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception Occured:" + ex.Message);
            }
        }       
    }
}



Thank you.

Related Post

0 comments:

Post a Comment