SPChangeCollection class
表示衍生自SPChange類別的物件集合。
Inheritance hierarchy
System.Object
Microsoft.SharePoint.Administration.SPAutoSerializingObject
Microsoft.SharePoint.SPBaseCollection
Microsoft.SharePoint.SPChangeCollection
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public NotInheritable Class SPChangeCollection _
Inherits SPBaseCollection
'用途
Dim instance As SPChangeCollection
public sealed class SPChangeCollection : SPBaseCollection
備註
使用SPList、 SPWeb、 SPSite或SPContentDatabase物件的GetChanges方法來傳回SPChangeCollection物件所做的變更發生在指定範圍內。然後列舉的集合,再個別檢查每個成員。
SPChangeCollection的GetChanges方法所傳回的每個物件是SPChange類別的子類別。父SPChange類別的屬性包含基本資訊的變更,包括變更的型別,如由ChangeType屬性 ;變更, Time屬性 ; 所表示的時間和位置變更,如SiteId屬性所表示的網站集合之識別碼。SPChange的子類別的屬性包含已變更的物件類型的特定資訊。例如, SPChangeItem類別代表的SPListItem物件的變更,因此擁有ListId屬性,識別清單項目已變更位置。同樣地, SPChangeList類別代表清單的變更,並具有識別網站的WebId屬性清單變更的位置。
可能很大,根據時段集中未曾為記錄檔和查詢的範圍保持對變更記錄的查詢所傳回的變更總數。基於效能考量,變更會傳回大小限制的批次。如果您想要的所有變更,而不是第一批次,則您的程式碼應該在直到它傳回零的變更,表示它已達到記錄結尾集合呼叫GetChanges方法在迴圈中。您可以使用從第一批次的最後變更的ChangeToken ,以此類推取得第二個批次,直到您取得空集合。
或者,您可以將SPChangeQuery物件傳遞至GetChanges方法。此物件具有屬性,您可以用來篩選依物件型別和變更類型的變更。您也可以調整設定SPChangeQuery物件的FetchLimit屬性傳回在單一往返集合的大小。
如需有關如何使用 [變更記錄檔的詳細資訊,請參閱Using the Change Log。
Examples
下列範例是一個簡單的主控台應用程式,查詢變更記錄的項目加入、 更新或刪除從指定的清單。擷取所做的變更之後, 應用程式會檢查每項變更,並列印日期的變更、 類型的變更,並已變更為主控台的項目名稱。
Imports System
Imports Microsoft.SharePoint
Module ConsoleApp
Sub Main()
Using siteCollection As SPSite = New SPSite("https://localhost")
Using webSite As SPWeb = siteCollection.OpenWeb()
' Get a list.
Dim list As SPList = webSite.Lists(0)
' Construct a query
Dim query As New SPChangeQuery(False, False)
' Specify the object type.
query.Item = True
' Specify change types.
query.Add = True
query.Delete = True
query.Update = True
Dim timeZone As SPTimeZone = webSite.RegionalSettings.TimeZone
Dim total As Integer = 0
' Loop until we reach the end of the log.
While True
Dim changes As SPChangeCollection = list.GetChanges(query)
total += changes.Count
' Print info about each change to the console.
For Each change As SPChangeItem In changes
' Get the item name.
Dim itemName As String = String.Empty
Dim item As SPListItem = Nothing
Try
item = list.GetItemByUniqueId(change.UniqueId)
itemName = item.Name
Catch ex As ArgumentException
itemName = "Unknown"
End Try
Console.WriteLine(vbCrLf + "Date: {0}", timeZone.UTCToLocalTime(change.Time).ToString())
Console.WriteLine("Change: {0}", change.ChangeType)
Console.WriteLine("Item: {0}", itemName)
Next change
' Break out of the loop when we fetch the last batch of changes.
If changes.Count < query.FetchLimit Then
Exit While
End If
' Go get another batch of changes starting where we left off.
query.ChangeTokenStart = changes.LastChangeToken
End While
Console.WriteLine(vbCrLf + "Total of {0:#,#} changes to {1} list", total, list.Title)
End Using
End Using
Console.Write(vbCrLf + "Press ENTER to continue...")
Console.ReadLine()
End Sub
End Module
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.