How to get changes from sharepoint 2010 client object model?

2.3k views Asked by At

Below is the code:

        ClientContext context = new ClientContext("http://SPSite");
        context.Credentials = new NetworkCredential("user", "pwd", "domain");
        ChangeQuery cq = new ChangeQuery(true, true);                  
        ChangeCollection col = list.GetChanges(cq);            
        context.Load(col);
        context.ExecuteQuery();
        MessageBox.Show(col.Count.ToString());

Irrespective of the changes done, it always shows 0.

1

There are 1 answers

3
Srikanth P Vasist On BEST ANSWER
ClientContext context = new ClientContext("http://SPSite");
context.Credentials = new NetworkCredential("user", "pwd", "domain");
ChangeQuery cq = new ChangeQuery(true, true); 
cq.ChangeTokenStart = new ChangeToken();
cq.ChangeTokenStart.StringValue = "1;3;" + list.Id.ToString() + ";" + DateTime.UtcNow.AddHours(-1).Ticks.ToString() + ";-1";                 
ChangeCollection col = list.GetChanges(cq);            
context.Load(col);
context.ExecuteQuery();
MessageBox.Show(col.Count.ToString());

Even though I don't prefer creating token by yourself, this seems to be the only way which works as per my googling so far.