SPFeatureCollection.Add method (Guid, Boolean, SPFeatureDefinitionScope)
Activates a feature by using the feature definition with the specified ID at the specified scope to create a new SPFeature object and then add it to the collection, optionally forcing activation even if there are errors.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
- Type: System.Boolean
true to force activation of the Feature even if there are errors; otherwise, false.
- Type: Microsoft.SharePoint.SPFeatureDefinitionScope
An enumeration value that indicates where the Feature definition is deployed. To activate an instance of a Feature that is made available through sandboxed solutions, pass SPFeatureDefinitionScope.Site as the argument. Otherwise, pass SPFeatureDefinitionScope.Farm.
The Feature is dependent on another Feature that has not been activated at this scope.
Feature definitions can be installed at either the farm level or the site-collection level. Use the FeatureDefinitions property of the SPFarm object to access the collection of SPFeatureDefinition objects that represent feature definitions installed at the farm level. Use the FeatureDefinitions property of the SPSite object to access the collection installed at the site-collection level.
A feature definition that is installed at the farm level can be activated for a Web application, a site collection, or a Web site. In all three cases, you must pass SPFeatureDefinitionScope.Farm in the featdefScope of the Add method. This parameter simply tells the Add method where to look for the feature definition.
A Feature definition that is installed at the site-collection level can be activated for a site collection or a Web site. In either case, you must pass SPFeatureDefinitionScope.Site in the featdefScope of the Add method.
To activate a Feature definition for a Web application, add it to the SPFeatureCollection object that is returned by the Features property of an SPWebApplication object. To activate it for a site collection, add it to the collection that is returned by the Features property of an SPSite object. To activate it for a Web site, add it to the collection that is returned by the Features property of an SPWeb object. The Add method throws an InvalidOperationException exception if the value of the Scope property of the SPFeatureDefinition object does not match the level of the collection to which you are adding the Feature.