SPFeature class
表示在其對應的範圍功能的狀態。
Inheritance hierarchy
System.Object
Microsoft.SharePoint.SPFeature
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public NotInheritable Class SPFeature
'用途
Dim instance As SPFeature
public sealed class SPFeature
備註
SPFeature物件集合,以在伺服器陣列、 Web 應用程式、 網站集合或網站層級中的目前狀態表示功能會啟動。缺乏SPFeature物件表示物件尚未啟動。
使用SPWebService、 SPWebApplication、 SPSite或SPWeb類別的Features屬性來取得啟動伺服器伺服陣列、 Web 應用程式、 網站集合或網站中的功能集合。使用SPContext類別的SiteFeatures或WebFeatures屬性來取得目前的網站集合或網站的功能集合。
使用索引子來從集合傳回單一的功能。例如,如果集合指派給一個名為collFeatures變數中,使用在 C# 的collFeatures[index]或在 Visual Basic,其中index是功能的 GUID 的collFeatures(index) 。
Examples
下列程式碼範例會安裝在伺服器伺服陣列中的功能,並啟動指定的網站中。
這個範例要求using指示詞 (在 Visual Basic 的Imports ) 的Microsoft.SharePoint和Microsoft.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。 |
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.