Export (0) Print
Expand All

SPFeatureCollection.Add method (Guid)

Activates a Feature by using the Feature definition with the specified ID to create a new SPFeature object and then add it to the collection.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public SPFeature Add(
	Guid featureId
)

Parameters

featureId
Type: System.Guid

The value of the Id property of an SPFeatureDefinition object.

Return value

Type: Microsoft.SharePoint.SPFeature
An object that represents the Feature instance. The FeatureDefinitionScope property of the SPFeature object is set to SPFeatureDefinitionScope.Farm.

ExceptionCondition
InvalidOperationException

The feature definition has not been installed in the server farm, or 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.

SPFeatureDependencyNotActivatedException

The Feature is dependent on another Feature that has not been activated at this scope.

Feature definitions can be deployed at the farm level or at the site-collection level. This overload of the Add method can be used only with Feature definitions that have been deployed at the farm level. To activate a feature using a Feature definition that is deployed at the site-collection level—that is, a Feature definition made available through sandboxed solutions—use the Add(Guid, Boolean, SPFeatureDefinitionScope) overload of the Add method.

You can get the collection of SPFeatureDefinition objects that represent feature definitions installed at the farm level by accessing the FeatureDefinitions property of the SPFarm object. A feature definition that is in the farm-level collection can be activated for a Web application, a site collection, or a Web site—as long as the Scope property of the SPFeatureDefinition object matches the level of the collection to which you are adding the feature.

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.

Show:
© 2014 Microsoft