将此功能升级到功能定义,(可选) 忽略引发的异常的当前安装的版本。
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
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
类型:System.Boolean如果true和异常发生,则应该正常块记录和被忽略的异常功能升级。然后尝试升级尽管异常的功能。这次尝试可能会或可能不成功,具体取决于异常将被忽略。
返回值
类型:System.Collections.Generic.IEnumerable<Exception>
在升级期间引发的异常的集合。例外情况出现,但不是会阻止功能的升级,因为它们是本质上是可以记录,并检查如果需要警告。如果发生异常,不会阻止升级,异常不包含在此集合中,但改为直接传递到调用方进行处理。
备注
由QueryFeaturesSPSite、 SPWebApplication、 SPWebService和SPContentDatabase类的方法返回的集合中的每个功能,您可以使用此方法。这些方法可以返回需要升级的功能的集合。您可以循环访问该集合并调用Upgrade方法来升级该集合中的功能。
示例
下面的示例获取一个服务器场范围集合包含所有实例的一种功能,需要升级。然后,该代码循环访问该集合,然后升级功能。
// 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