Contains the base definition of an
SPFeature, including its name, identifier, scope, and version.
Namespace: Microsoft.SharePoint.Administration
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Visual Basic (Declaration)
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel:=True)> _
Public NotInheritable Class SPFeatureDefinition
Inherits SPPersistedObject
Dim instance As SPFeatureDefinition
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)]
public sealed class SPFeatureDefinition : SPPersistedObject
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.
Caution: |
|---|
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. |
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>");
System.Object
Microsoft.SharePoint.Administration.SPAutoSerializingObject
Microsoft.SharePoint.Administration.SPPersistedObject
Microsoft.SharePoint.Administration.SPFeatureDefinition
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.