共用方式為


SPFeature.Upgrade method

將這項功能升級為目前安裝的功能定義,並選擇性忽略例外狀況,如果其中一個就會擲回的版本。

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'宣告
Public Function Upgrade ( _
    force As Boolean _
) As IEnumerable(Of Exception)
'用途
Dim instance As SPFeature
Dim force As Boolean
Dim returnValue As IEnumerable(Of Exception)

returnValue = instance.Upgrade(force)
public IEnumerable<Exception> Upgrade(
    bool force
)

參數

  • force
    Type: System.Boolean

    如果true和例外狀況發生時,會正常區塊升級的功能,例外狀況是記錄且忽略。再嘗試升級的功能,儘管例外狀況。這項嘗試可能會或可能不會成功,根據例外狀況會被忽略。

傳回值

Type: System.Collections.Generic.IEnumerable<Exception>
在升級期間擲回的例外狀況的集合。例外狀況發生,但不是會封鎖功能的升級,因為它們是基本上可以登入並檢閱如果想要的警告。如果發生例外狀況,並封鎖升級,例外狀況並不包含在這個集合,但改為直接傳遞至呼叫端處理。

備註

您可以使用這個方法上的SPSiteSPWebApplicationSPWebServiceSPContentDatabase類別的QueryFeatures方法所傳回之集合中每一項功能。這些方法可以傳回版本需要升級的功能的集合。您可以逐一查看該集合,並呼叫Upgrade方法,以升級集合中的功能。

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

請參閱

參照

SPFeature class

SPFeature members

Microsoft.SharePoint namespace