Usando alterações para consultas para objetos
O log de alteração fornece informações sobre os objetos que foram alterados: o tipo de cada objeto, sua GUID e a GUID de seu objeto pai. O cliente pode usar esses valores para recuperar o objeto.
O seguinte exemplo ilustra como um cliente pode usar o objeto SPChange T:Microsoft.SharePoint.SPChange para recuperar seu correspondente objeto SharePoint.
Dim mySiteCollection As New SPSite("http://siteUrl")
Dim myWebSite As SPWeb = mySiteCollection.RootWeb
Dim initToken As SPChangeToken = myWebSite.CurrentChangeToken
' Changing the title of the web.
myWebSite.Title = "My New Title"
myWebSite.Update()
Dim changes As SPChangeCollection = myWebSite.GetChanges(initToken)
Dim changedObject As SPChangeWeb = Nothing
Dim changedObjectGuid As New Guid()
Dim changedObjectSiteId As New Guid()
Dim change As SPChange
For Each change In changes
If TypeOf change Is Microsoft.SharePoint.SPChangeWeb Then
changedObject = CType(change, SPChangeWeb)
changedObjectGuid = changedObject.Id
changedObjectSiteId = changedObject.SiteId
End If
Next change
' Now that we have the GUIDs of the changed object
'and its parent object, we can retrieve the objects.
Dim changedSite As New SPSite(changedObjectSiteId)
Dim changedWebSite As SPWeb = changedSite.AllWebs(changedObjectGuid)
SPSite mySiteCollection = new SPSite("http://siteUrl");
SPWeb myWebSite = mySiteCollection.RootWeb;
SPChangeToken initToken = myWebSite.CurrentChangeToken;
/* Changing the title of the web.*/
myWebSite.Title = "My New Title";
myWebSite.Update();
SPChangeCollection changes = myWebSite.GetChanges(initToken);
SPChangeWeb changedObject = null;
Guid changedObjectGuid = new Guid();
Guid changedObjectSiteId = new Guid();
foreach (SPChange change in changes)
{
if (change is Microsoft.SharePoint.SPChangeWeb)
{
changedObject = (SPChangeWeb)change;
changedObjectGuid = changedObject.Id;
changedObjectSiteId = changedObject.SiteId;
}
}
/* Now that we have the GUIDs of the changed object
and its parent object, we can retrieve the objects.*/
SPSite changedSite = new SPSite(changedObjectSiteId);
SPWeb changedWebSite = changedSite.AllWebs[changedObjectGuid];