in SharePoint 2010

SharePoint 2010: Lists.GetListItemChangesWithKnowledge Method

SharePoint 2010 has its own sync provider built in which is consumed by other client applications such as SharePoint Workspace 2010. You can read the case study here.

 

Microsoft Uses Sync Framework to Create New Collaboration Solution

As Microsoft, the world leader in software for personal and business computing, prepared the next version of its Microsoft® Office suite of desktop applications it wanted to combine the functionality of two of its most popular collaboration tools: Microsoft SharePoint® Server and Microsoft Groove®. The company’s development teams, however, faced the challenge of handling data synchronization to ensure version control. They found the technology they needed with the Microsoft Sync Framework, a technology developed by the Microsoft Sync Framework group, which is part of the Microsoft SQL Azure™ team. The result is Microsoft SharePoint Workspace 2010, which provides the rich user experience of a desktop application, with the Sync Framework handling data synchronization with sites created using SharePoint Server 2010.

 

As a developer if you want to make use of this in-built sync framework to build your SharePoint client applications, you can do so! Let me introduce to the new Lists.asmx method: GetListItemChangesWithKnowledge. This method returns all of the list items that meet specified criteria and that have changed since the date-time specified in the knowledge parameter for the specified list. You can read this blog post to know more about the sync knowledge.

 

GetListItemChangesWithKnowledge Usage:

 

To use this method, you need to add reference to the Lists.asmx web service to your application: http://<site-name>/_vti_bin/Lists.asmx

 

After that you can use the method as follows:

 

using (Lists list = new Lists())
{
  list.Credentials = new NetworkCredential("username", "password", "domain");

  changedItems = listTLA.GetListItemChangesWithKnowledge("Projects", null, null, null, 
                                                          null, null, null, null, null);
}

 

You can pass null for every parameter except for the first one which is the name of the list. As you can see we are passing null for the sync knowledge too. Initially, we can pass to get all the items (which are new). The method will also return the sync knowledge which then you can use for the subsequent calls. Below is an example of what we get back the first time:

 

<Changes xmlns="http://schemas.microsoft.com/sharepoint/soap/">
    <MadeWithKnowledge>
        <sync:syncKnowledge xmlns=http://schemas.microsoft.com/2008/03/sync/ 
                             xmlns:sync="http://schemas.microsoft.com/2008/03/sync/">
            <idFormatGroup>
                <replicaIdFormat sync:isVariable="false" sync:maxLength="16" />
                <itemIdFormat sync:isVariable="false" sync:maxLength="16" />
                <changeUnitIdFormat sync:isVariable="false" sync:maxLength="1" />
            </idFormatGroup>
            <replicaKeyMap>
                <replicaKeyMapEntry sync:replicaId="jeJVN1EeT3Sn+NBWZOmqoA==" sync:replicaKey="0" />
            </replicaKeyMap>
            <clockVector>
                <clockVectorElement sync:replicaKey="0" sync:tickCount="1589" />
            </clockVector>
        </sync:syncKnowledge>
    </MadeWithKnowledge>
</Changes>
<rs:data ItemCount="1" xmlns:rs="urn:schemas-microsoft-com:rowset">
    <z:row ows_Attachments="0"
           ows_LinkTitle="Kim Abercrombie"
           ows_JobTitle="Test Lead"
           ows_Team="AP"
           ows_Contribution_x0020__x0028_in_x00="2.00000000000000"
           ows_Project="1;#Writing more sample code"
           ows__ModerationStatus="0"
           ows__Level="1"
           ows_Title="Kim Abercrombie"
           ows_ID="1"
           ows_UniqueId="1;#{92367B48-BF4E-4EB7-A653-EDD777CE4612}"
           ows_owshiddenversion="1"
           ows_FSObjType="1;#0"
           ows_Created_x0020_Date="1;#2010-03-15T01:13:36Z"
           ows_Created="2010-03-15T01:13:36Z"
           ows_FileLeafRef="1;#1_.000"
           ows_PermMask="0x7fffffffffffffff"
           ows_Modified="2010-03-15T01:13:36Z"
           ows_FileRef="1;#Lists/Employees/1_.000"
           ows_MetaInfo="1;#"
           ows_ServerRedirected="0"
           xmlns:z="#RowsetSchema" />

</rs:data>

 

As you can see, the sync knowledge associated is the sync:syncKnowledge parameter. You can use this parameter from now on to get updates on this list by passing it into the GetListItemChangesWithKnowledge method.

 

If you had a delete, the returned XML will look like:

 

<Changes ServerTime="20100421 10:35:49">
    <Id ChangeType="Delete" ServerChangeUnit="{E5C5E20A-5A9F-406C-B9F6-28923750CECD}:3510" 
                               UniqueId="{94512989-20A7-4BF3-9C13-AEB8BADD1F7C}">4</Id>
        <MadeWithKnowledge>
            <sync:syncKnowledge xmlns=http://schemas.microsoft.com/2008/03/sync/ 
                               xmlns:sync="http://schemas.microsoft.com/2008/03/sync/">

 

You can get the Delete event under the Changes parameter.

 

In the coming weeks, I will be blogging on building a SharePoint 2010 sync client application using the GetListItemChangesWithKnowledge method.

Write a Comment

Comment

Time limit is exhausted. Please reload the CAPTCHA.

  1. I know it’s been a while from this post, but do you in any chance have any working sample for sync? My confusion starts with custom sync provider proxy that has to be written in order to work against sharepoint data (which is, in itself, solution for the problem) – what are the methods which have to be implemented, and how those methods map to sharepoint web services. on client side, situation is clear, as locally file sync provider can be used.