Created
December 31, 2015 17:53
-
-
Save sksnips/0de89669aa5a4415a484 to your computer and use it in GitHub Desktop.
Retrieve all the changes (add, update & delete) occurred on the list item using CSOM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//CSOM Assembly version - 16.1.4727.1200 | |
//using Microsoft.SharePoint.Client; | |
//using System.Net | |
//GetItemChanges(credentials, weburl, listtitle, itemid); | |
//This method returns all the changes (add, update & delete) happened to the list item | |
private static void GetItemChanges(ICredentials credentials, string weburl, string listTitle, int itemid) | |
{ | |
using (ClientContext ctx = new ClientContext(weburl)) | |
{ | |
ctx.Credentials = credentials; | |
Web oweb = ctx.Web; | |
ListCollection lists = oweb.Lists; | |
List targetList = lists.GetByTitle(listTitle); | |
ListItem targetItem = targetList.GetItemById(itemid); | |
//ChangeQuery helps the method gets the changes by setting appropriate property as true | |
ChangeQuery cq = new ChangeQuery(); | |
cq.Item = true; | |
cq.Add = true; | |
cq.Update = true; | |
cq.DeleteObject = true; | |
//SP.ListItem.GetChanges(ChangeQuery) - Method available from CSOM Assembly version - 16.1.4727.1200 | |
ChangeCollection cc = targetItem.GetChanges(cq); | |
ctx.Load(cc); | |
ctx.ExecuteQuery(); | |
Console.WriteLine(cc.Count.ToString()); | |
} | |
Console.WriteLine("Press any key to exit..."); | |
Console.Read(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to get the deleted filename?
I'm getting notification through Webhook whenever the file is added/modifed in Sharepoint. This is working fine.
But whenever the file is deleted, it's getting failed since the file itself not present when it is deleted.