Share via


SPFeatureDefinition Class

Contains the base definition of a feature, including its name, ID, scope, and version.

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.Administration.SPAutoSerializingObject
    Microsoft.SharePoint.Administration.SPPersistedObject
      Microsoft.SharePoint.Administration.SPFeatureDefinition

Namespace:  Microsoft.SharePoint.Administration
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
<GuidAttribute("6F6F021A-1055-4718-AB6E-FE85743C5FD9")> _
<SubsetCallableTypeAttribute> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class SPFeatureDefinition _
    Inherits SPPersistedObject
'Usage
Dim instance As SPFeatureDefinition
[GuidAttribute("6F6F021A-1055-4718-AB6E-FE85743C5FD9")]
[SubsetCallableTypeAttribute]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class SPFeatureDefinition : SPPersistedObject

Remarks

Use the FeatureDefinitions property of the SPFarm class to get the collection of feature definitions that are installed in the server farm. To add a feature definition to the collection, use one of the Add methods of the SPFeatureDefinitionCollection class. Adding a feature to the collection installs the feature in the server farm, making it available for activation in its specified scope. Adding a feature that has farm scope not only installs the feature, but activates it within the farm.

Use an indexer to return a single feature definition from the collection. For example, if the collection is assigned to a variable named myDefinitions, use myDefinitions[index] in C#, or myDefinitions(index) in Visual Basic, where index is the GUID of the feature.

Warning

You cannot use the SPFeatureDefinition constructor to create a feature definition object. This is not supported and returns a NullReferenceException if you attempt to implement members of an object created through the constructor.

Examples

The following example installs a feature definition in the server farm. The example assumes that a custom folder has been added to the features directory that contains a Feature.xml file specifying a GUID for the feature. This example requires using directives (Imports in Visual Basic for both the Microsoft.SharePoint and Microsoft.SharePoint.Administration namespaces.

[C#]

System.Globalization.CultureInfo cInfo = new System.Globalization.CultureInfo(1033);

SPFeatureDefinitionCollection farmFeatures = SPFarm.Local.FeatureDefinitions;

Guid farmGuid = new Guid("BCFC1029-7DB4-4e9c-B162-B03CE8497DAC");

SPFeatureDefinition featureDefinition = farmFeatures.Add(@"Feature_Folder\Feature.xml", farmGuid, true);

Response.Write("Farm definition " + SPEncode.HtmlEncode(featureDefinition.GetTitle(cInfo)) + " added.<BR>");

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

SPFeatureDefinition Members

Microsoft.SharePoint.Administration Namespace