How to get changes from SP server 2010 in client object model?
-
09-12-2019 - |
Question
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.
Solution 2
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();
ChangeToken endToken;
foreach(Change change in col)
{
endToken = change.ChangeToken;// endToken serves as next start token for further logs.
// Do your stuffs here.
}
This can be the appropriate solution.
OTHER TIPS
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange