Compartir a través de


Using Changes to Query for Objects

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The Change Log provides information about the objects that have changed: the type of each object, its GUID, and the GUID of its parent object. The client can use these values to retrieve the object.

The following example illustrates how a client can use the SPChange object to retrieve its corresponding SharePoint object.

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];