Synchronization: Getting changes from WebDAV Server with Collection Synchronization Support

In this article we describe how to request changes from a WebDAV server that supports collection synchronization. 

To get changes from the server, the WebDAV Client Library provides WebDavSession.GetChangesAsync() method. This method allows getting all changes from server that happened since provided sync token:

// Specify extra properties that you want to get with each changed item.
// Typically you want to have at least an ID of each file/folder.
PropertyName[] propNames = new PropertyName[2];
propNames[0] = new PropertyName("resource-id", "DAV:");
propNames[1] = new PropertyName("parent-resource-id", "DAV:");
string syncToken = // The sync token value to start getting changes.
long limit = 100; // Max number of changes to return. 
bool deep = true; // Immediate children or entire subtree.

IChanges davChanges = await Session.GetChangesAsync(
    new Uri("https://server/"), 

// Apply changes on the client.
foreach (IChangedItem remoteStorageItem in davChanges)
    if (remoteStorageItem.ChangeType == Change.Changed)
        // The item is updated, created or moved/renamed.           
        // The item is deleted.

// Save a new sync token returned from the server on the client,
// send it to the server in the next request.
string newSyncToken = davChanges.NewSyncToken;

See Also: