This topic has not yet been rated - Rate this topic

SPFeatureDefinition Class

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

Namespace:  Microsoft.SharePoint.Administration
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
[GuidAttribute("6F6F021A-1055-4718-AB6E-FE85743C5FD9")]
[SubsetCallableTypeAttribute]
[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 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.

Caution noteCaution

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>");
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.