SPChange class
代表已有項目、 清單、 網站、 網站集合或內容資料庫的範圍內的 SharePoint 物件或 Web 應用程式的範圍內的安全性原則的變更。
Inheritance hierarchy
System.Object
Microsoft.SharePoint.SPChange
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Class SPChange
'用途
Dim instance As SPChange
public class SPChange
備註
SPChange類別的子類別代表SharePoint Foundation變更記錄檔中的每個項目。父SPChange類別的屬性包含的變更,包括的變更,類型,如ChangeType屬性 ; 所表示的基本資訊變更,如Time屬性 ; 所表示的時間與位置進行變更,如SiteId屬性所代表之網站集合的識別碼。
SPChange的子類別的屬性包含專用的已變更的物件類型的資訊。例如, SPChangeItem類別SPListItem物件代表的變更與因此具有ListId屬性,識別清單項目變更的所在。同樣地, SPChangeList類別代表對清單的變更,並已識別網站的WebId屬性清單變更的所在。
變更記錄檔沒有記錄所有 SharePoint 的物件,僅選取的物件類型的變更。追蹤修訂記錄中的物件類型列示於下表,以及其代表變更SPChange的子類別。
指明 |
代表的變更 |
---|---|
SPAlert物件。 |
|
SPField物件。 |
|
已存在外部清單,並沒有對應的項目SPFile物件。 |
|
已存在外部清單,並沒有對應的項目SPFolder物件。 |
|
SPGroup物件。 |
|
SPListItem物件及檔案,可能會有其相關的資料夾。 |
|
SPList物件。 |
|
SPPolicy物件。 |
|
SPSite物件。 |
|
SPUser物件。 |
|
SPView物件。 |
|
SPWeb物件。 |
使用GetChangesSPList、 SPWeb、 SPSite或SPContentDatabase物件方法可傳回SPChangeCollection物件在指定的範圍內發生的變更。您可以再列舉集合,並檢查其成員的每個個別。
總數對變更記錄的查詢所傳回的變更可能是非常大,根據保留期間設定的記錄檔和查詢的範圍。基於效能考量,變更會傳回在有限的大小的批次。如果您要的所有變更,而不是第一個批次,則您的程式碼應該在直到它將會傳回零表示它已到達結尾的記錄檔的變更與呼叫GetChanges方法循環。您可以使用從第一個批次的最後一個修訂ChangeToken依此類推取得第二個批次,直到到達空集合。
或者,您可以SPChangeQuery將物件傳遞至GetChanges方法。此物件有一些您可以使用篩選變更依物件類型及變更類型的屬性。您也可以調整藉由設定SPChangeQuery物件的FetchLimit屬性會傳回單一的來回集合的大小。
For more information about working with the change log, see Using the Change Log.
Examples
下列範例會擷取內容資料庫的變更記錄檔中的所有項目,並列印主控台每項變更的相關資訊。
using System;
using Microsoft.SharePoint;
namespace Test
{
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("https://localhost"))
{
using (SPWeb web = site.RootWeb)
{
// Construct a query.
SPChangeQuery query = new SPChangeQuery(true, true);
SPTimeZone timeZone = web.RegionalSettings.TimeZone;
long total = 0;
// Get changes in batches.
while (true)
{
// Fetch a set of changes.
SPChangeCollection changes = site.ContentDatabase.GetChanges(query);
total += changes.Count;
// Write info about each change to the console.
foreach (SPChange change in changes)
{
// Print the date of the change.
Console.WriteLine("\nDate: {0}",
timeZone.UTCToLocalTime(change.Time).ToString());
// Print the ID of the site where the change took place.
Console.WriteLine("Site ID: {0}", change.SiteId.ToString("B"));
// Print the type of object that was changed.
// GetType().Name returns SPChangeItem, SPChangeList, etc.
// Remove the "SPChange" part of the name.
string objType = change.GetType().Name.Replace("SPChange", null);
Console.WriteLine("Type of object: {0}", objType);
// Print the nature of the change.
Console.WriteLine("Type of change: {0}", change.ChangeType.ToString());
}
// Break out of loop if we have the last batch
if (changes.Count < query.FetchLimit)
break;
// Otherwise, go get another batch
query.ChangeTokenStart = changes.LastChangeToken;
}
Console.WriteLine("\nTotal changes: {0}", total);
}
}
Console.Write("\nPress ENTER to continue...");
Console.ReadLine();
}
}
}
Imports System
Imports Microsoft.SharePoint
Module Test
Sub Main()
Using site As SPSite = New SPSite("http://lswss5/sites/don")
Using web As SPWeb = site.RootWeb
' Construct a query.
Dim query As SPChangeQuery = New SPChangeQuery(True, True)
Dim timeZone As SPTimeZone = web.RegionalSettings.TimeZone
Dim total As Long = 0
' Get changes in batches.
While True
' Fetch a set of changes.
Dim changes As SPChangeCollection = site.ContentDatabase.GetChanges(query)
total += changes.Count
' Write info about each change to the console.
Dim change As SPChange
For Each change In changes
' Print the date of the change.
Console.WriteLine(vbCrLf + "Date: {0}", _
timeZone.UTCToLocalTime(change.Time).ToString())
' Print the ID of the site where the change took place.
Console.WriteLine("Site ID: {0}", change.SiteId.ToString("B"))
' Print the type of object that was changed.
' GetType().Name returns SPChangeItem, SPChangeList, etc.
' Remove the "SPChange" part of the name.
Dim objType As String = change.GetType().Name.Replace("SPChange", Nothing)
Console.WriteLine("Type of object: {0}", objType)
' Print the nature of the change.
Console.WriteLine("Type of change: {0}", change.ChangeType.ToString())
Next
' Break out of loop if we have the last batch
If changes.Count < query.FetchLimit Then
Exit While
End If
' Otherwise, go get another batch
query.ChangeTokenStart = changes.LastChangeToken
End While
Console.WriteLine(vbCrLf + "Total changes: {0}", total)
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.
請參閱
參照
Microsoft.SharePoint namespace
其他資源
Inheritance hierarchy
System.Object
Microsoft.SharePoint.SPChange
Microsoft.SharePoint.SPChangeAlert
Microsoft.SharePoint.SPChangeContentType
Microsoft.SharePoint.SPChangeField
Microsoft.SharePoint.SPChangeFile
Microsoft.SharePoint.SPChangeFolder
Microsoft.SharePoint.SPChangeGroup
Microsoft.SharePoint.SPChangeItem
Microsoft.SharePoint.SPChangeList
Microsoft.SharePoint.SPChangeSecurityPolicy
Microsoft.SharePoint.SPChangeSite
Microsoft.SharePoint.SPChangeUser
Microsoft.SharePoint.SPChangeView
Microsoft.SharePoint.SPChangeWeb