Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Feature Object Model

Last modified: February 15, 2010

Applies to: SharePoint Foundation 2010

In this article
Feature Classes
Accessing Feature Collections

Microsoft SharePoint Foundation offers a full object model for discovering the list of installed features within a given scope, and for controlling whether features are enabled at the farm and site levels.

Get the collection of features for a farm, SharePoint Foundation Web application, site collection, or Web site by using one of the following properties to access the collection:

The following example displays the list of names and the GUIDs of all the features that are activated on a specified site:

SPSite siteCollection = SPControl.GetContextSite(Context);
SPWeb site = siteCollection.AllWebs["Site"];
SPFeatureCollection siteFeatures = site.Features;
System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo.GetCultureInfo("en-US");

foreach (SPFeature siteFeature in siteFeatures)
   Response.Write("Title: " + siteFeature.Definition.GetTitle(cultureInfo) + "<BR>ID:" + siteFeature.DefinitionId.ToString() + "<BR><BR>");

The next example uses information returned through the previous example to add a feature to a subsite:

SPWeb subSite = site.Webs["SubSite"];
System.Guid guid = new System.Guid("6e005f62-f8b2-4073-a673-c035c9129946");
© 2015 Microsoft