SPFeature 类

代表在其相应的作用域特征的状态。

继承层次结构

System.Object
  Microsoft.SharePoint.SPFeature

命名空间:  Microsoft.SharePoint
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
Public NotInheritable Class SPFeature
用法
Dim instance As SPFeature
public sealed class SPFeature

备注

SPFeature对象在服务器场、 Web 应用程序、 网站集或网站级别集合中存在表明该功能已激活。SPFeature对象缺乏指示未激活的对象。

使用Features的SPWebServiceSPWebApplicationSPSiteSPWeb的类的属性获取在服务器场、 Web 应用程序、 网站集或网站中激活的功能的集合。使用SiteFeaturesWebFeaturesSPContext类的属性获取当前网站集或网站的功能的集合。

使用索引器从集合中返回单个功能。例如,如果该集合分配给名为collFeatures的变量中,使用在 C# collFeatures[index]或collFeatures(index)在 Visual Basic,其中index是该功能的 GUID。

示例

下面的代码示例在该服务器场中安装一种功能,并指定网站中激活它。

此示例要求using指令 (在 Visual Basic 中的Imports ) 的Microsoft.SharePointMicrosoft.SharePoint.Utilities的命名空间。

System.Globalization.CultureInfo oCultureInfo = new System.Globalization.CultureInfo(1033);
SPFeatureDefinitionCollection collFeatureDefinitions = SPFarm.Local.FeatureDefinitions;

Guid guidFeatureID = new Guid("3C4CD219-D8A7-4fef-BED4-ABA672F7A21A");

SPFeatureDefinition oFeatureDefinition = 
  collFeatureDefinitions.Add("Feature_Folder\\feature.xml", guidFeatureID);

Response.Write(SPEncode.HtmlEncode(oFeatureDefinition.GetTitle(oCultureInfo)) + " installed.<BR>");

SPFeatureCollection collFeatures = SPContext.Current.Site.AllWebs["Site"].Features;
SPFeature oFeature = collFeatures.Add(guidFeatureID);

Response.Write(SPEncode.HtmlEncode(oFeature.Definition.GetTitle(oCultureInfo)) + " activated.<BR>");
Dim oCultureInfo As New System.Globalization.CultureInfo(1033)
Dim collFeatureDefinitions As SPFeatureDefinitionCollection = SPFarm.Local.FeatureDefinitions

Dim guidFeatureID As New Guid("3C4CD219-D8A7-4fef-BED4-ABA672F7A21A")

Dim oFeatureDefinition As SPFeatureDefinition = collFeatureDefinitions.Add("Feature_Folder\feature.xml", guidFeatureID)

Response.Write(SPEncode.HtmlEncode(oFeatureDefinition.GetTitle(oCultureInfo)) & " installed.<BR>")

Dim collFeatures As SPFeatureCollection = SPContext.Current.Site.AllWebs("Site").Features
Dim oFeature As SPFeature = collFeatures.Add(guidFeatureID)

Response.Write(SPEncode.HtmlEncode(oFeature.Definition.GetTitle(oCultureInfo)) & " activated.<BR>")

备注

某些对象实现IDisposable接口,并必须避免后不再需要保留这些对象在内存中。好的编码做法有关的信息,请参阅Disposing Objects

线程安全性

该类型的任何公共 静态 (已共享 在 Visual Basic 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。

另请参阅

引用

SPFeature 成员

Microsoft.SharePoint 命名空间