SPFeature.Version property
取得目前版本的功能。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Property Version As Version
Get
Friend Set
'用途
Dim instance As SPFeature
Dim value As Version
value = instance.Version
public Version Version { get; internal set; }
Property value
Type: System.Version
功能的版本。
備註
這個屬性的值可以是不同的基礎功能定義Version屬性的值。例如,您可能會部署功能定義使用版本號碼為 1 的功能。此時,功能執行個體和功能定義具有相同的版本號碼。假設接下來您修改功能定義,並重新部署它與版本號碼為 2。功能定義現在是版本 2,但功能執行個體保持第 1 版。差異表示功能執行個體需要升級。您需要執行功能升級程式碼,變更功能的執行個體的版本從 1 到 2。
Examples
下列範例會取得整個伺服陣列的集合,包含所有功能,需要升級的執行個體。然後程式碼會逐一查看集合,並升級功能。
// Represent the ID of the Feature we want to upgrade.
Guid featureId = new Guid("1B006A62-7B92-475c-A2E5-A1CF03EE0887");
// Get the default Web service in the farm.
SPWebService webService = SPFarm.Local.Services.GetValue<SPWebService>("");
// Get all Feature instances with the specified ID that require upgrade.
SPFeatureQueryResultCollection features = webService.QueryFeatures(featureId, true);
// Get a Features enumerator.
IEnumerator<SPFeature> featureEnumerator = features.GetEnumerator();
while (featureEnumerator.MoveNext())
{
// Get current Feature.
SPFeature feature = featureEnumerator.Current;
// Upgrade the current Feature.
Console.WriteLine("Upgrading Feature {0} with ID {1}.",
feature.Definition.DisplayName, feature.DefinitionId);
Console.WriteLine("Feature Version Before Upgrade: {0}", feature.Version);
feature.Upgrade(false);
Console.WriteLine("Feature Version After Upgrade: {0}", feature.Version);
}
' Represent the ID of the Feature we want to upgrade.
Dim featureId As New Guid("1B006A62-7B92-475c-A2E5-A1CF03EE0887")
' Get the default Web service in the farm.
Dim webService As SPWebService = SPFarm.Local.Services.GetValue(Of SPWebService)("")
' Get all Feature instances with the specified ID that require upgrade.
Dim features As SPFeatureQueryResultCollection = webService.QueryFeatures(featureId, True)
' Get a Features enumerator.
Dim featureEnumerator As IEnumerator(Of SPFeature) = features.GetEnumerator()
Do While featureEnumerator.MoveNext()
' Get current Feature.
Dim feature As SPFeature = featureEnumerator.Current
' Upgrade the current Feature.
Console.WriteLine("Upgrading Feature {0} with ID {1}.", feature.Definition.DisplayName, feature.DefinitionId)
Console.WriteLine("Feature Version Before Upgrade: {0}", feature.Version)
feature.Upgrade(False)
Console.WriteLine("Feature Version After Upgrade: {0}", feature.Version)
Loop