My scenario is i have a list of companies and each time am creating a new company(folder),i should be able to use the changequery method to identify the company created and create a document set inside it. i can get the number of changes correctly using the first log.Info() but log.Info("folder is "+folder.Name); is displaying only the first folder i created!!!
try { log.Info("Executing function"); using (var ctx = await csomHelper.GetClientContext("site url")) { ListCollection list = ctx.Web.Lists; List targetlist = list.GetByTitle("Companies"); log.Info(""); ChangeQuery cq = new ChangeQuery(false, false); cq.Item = true; cq.Folder = true; cq.File = true; cq.List = true; cq.Add = true; ctx.Load(targetlist); ctx.ExecuteQuery(); ChangeCollection coll = targetlist.GetChanges(cq); ctx.Load(coll); ctx.ExecuteQuery(); log.Info(coll.Count.ToString()); foreach (Change change in coll) { if (change is ChangeItem) { ListItem changedListItem = targetlist.GetItemById((change as ChangeItem).ItemId); ctx.Load(changedListItem); ctx.ExecuteQuery(); if (changedListItem.FileSystemObjectType == FileSystemObjectType.Folder){ Folder folder=changedListItem.Folder; ctx.Load(folder); ctx.ExecuteQuery(); log.Info("folder is "+folder.Name); ctx.Load(targetlist,l => l.RootFolder,l => l.ContentTypes); ctx.ExecuteQuery(); var ctData = targetlist.ContentTypes.Where(c => c.Name == "thirdcorporate"); var contentType = ctData.FirstOrDefault(); ctx.Load(contentType); ctx.ExecuteQuery(); DocumentSet.Create(ctx, folder, "newshi Documents", contentType.Id); ctx.ExecuteQuery(); } else { log.Info("not a folder"); }