Share via


Feature Object Model

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Windows SharePoint Services (version 3) 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.

Feature Classes

Accessing Feature Collections

Get the collection of features for a farm, Windows SharePoint Services Web application (virtual server), site collection, or site by using one of the following properties to access the collection:

Example

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(1033);

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");
subSite.Features.Add(guid);