Share via


SPFeatureDefinition Class

Contains the base definition of an SPFeature, including its name, identifier, 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)

Syntax

<GuidAttribute("6F6F021A-1055-4718-AB6E-FE85743C5FD9")> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class SPFeatureDefinition _
    Inherits SPPersistedObject

Dim instance As SPFeatureDefinition
[GuidAttribute("6F6F021A-1055-4718-AB6E-FE85743C5FD9")]
[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 SPFeatureDefinitionCollection 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

Other Resources

Feature Object Model