Friday, August 3, 2012

SharePoint2010 Get the list of Farm Scoped Features using object model

Scenario: How to programatically get the list of Farm Scoped features using object model

Solution: Getting the list of farm scoped features programatically is different than getting the list of site, web scoped features.
Here is how you can get the list of farm scoped features

SPFeatureCollection myFarmFeatures = mySite.WebApplication.WebService.Features;

With in Feature event handlers
using Microsoft.Sharepoint.Administration;

SPWebService svc = properties.Feature.Parent as SPWebService;

svc.Features.Add("Feature Guid");


foreach (var feature in svc.Features)
{
  //your code here           

} 

 "svc.Features.Add" will activate the feature at farm scope.

No comments:

Post a Comment