/// <summary> /// Process ListItem one by one /// </summary> /// <param name="listName">ListName</param> /// <param name="camlQuery">CamlQuery</param> /// <param name="itemProcessor">itemprocessor delegate</param> /// <param name="errorCallout">error delegate</param> public void ProcessListItem(string listName, CamlQuery camlQuery, ItemProcessor itemProcessor, ref List <PeoplePickerListOutput> lstPeoplepickeroutput, ItemProcessorErrorCallout errorCallout) { List list = _context.Web.Lists.GetByTitle(listName); CamlQuery query = camlQuery; //EventReceiverDefinitionCollection erCollection = list.EventReceivers; //foreach(EventReceiverDefinition erDefinition in erCollection) //{ // erDefinition. //} ListItemCollectionPosition position = null; query.ListItemCollectionPosition = position; while (true) { ListItemCollection listItems = list.GetItems(query); _context.Load(listItems, items => items.ListItemCollectionPosition); _context.ExecuteQuery(); for (int i = 0; i < listItems.Count; i++) { try { itemProcessor(listItems[i], _context, ref lstPeoplepickeroutput); } catch (System.Exception ex) { if (errorCallout == null || errorCallout(listItems[i], ex)) { throw; } } } if (listItems.ListItemCollectionPosition == null) { return; } else { /*if query contains lookup column filter last batch returns null * by removing the lookup column in paginginfo query will return next records */ string pagingInfo = listItems.ListItemCollectionPosition.PagingInfo; string[] parameters = pagingInfo.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries); List <string> requiredParameters = new List <string>(); foreach (string str in parameters) { if (str.Contains("Paged=") || str.Contains("p_ID=")) { requiredParameters.Add(str); } } pagingInfo = string.Join("&", requiredParameters.ToArray()); listItems.ListItemCollectionPosition.PagingInfo = pagingInfo; query.ListItemCollectionPosition = listItems.ListItemCollectionPosition; } } }
public void ProcessListItems(SPList list, bool fIterateInReverseOrder, ItemProcessor itemProcessor, ItemProcessorErrorCallout errorCallout) { if (list == null) { throw new ArgumentNullException("list"); } if (itemProcessor == null) { throw new ArgumentNullException("itemProcessor"); } string strQuery = !list.HasExternalDataSource ? ItemEnumerationOrderById : null; ProcessListItems(list, strQuery, true, items => ProcessItems(items, false, fIterateInReverseOrder, itemProcessor, errorCallout), (items, e) => true); }
/// <summary> /// Process ListItem one by one /// </summary> /// <param name="listName">ListName</param> /// <param name="camlQuery">CamlQuery</param> /// <param name="itemProcessor">itemprocessor delegate</param> /// <param name="errorCallout">error delegate</param> public void ProcessListItem(string listName, CamlQuery camlQuery, ItemProcessor itemProcessor,ref List<PeoplePickerListOutput> lstPeoplepickeroutput, ItemProcessorErrorCallout errorCallout) { List list = _context.Web.Lists.GetByTitle(listName); CamlQuery query = camlQuery; //EventReceiverDefinitionCollection erCollection = list.EventReceivers; //foreach(EventReceiverDefinition erDefinition in erCollection) //{ // erDefinition. //} ListItemCollectionPosition position = null; query.ListItemCollectionPosition = position; while (true) { ListItemCollection listItems = list.GetItems(query); _context.Load(listItems, items => items.ListItemCollectionPosition); _context.ExecuteQuery(); for (int i = 0; i < listItems.Count; i++) { try { itemProcessor(listItems[i], _context, ref lstPeoplepickeroutput); } catch (System.Exception ex) { if (errorCallout == null || errorCallout(listItems[i], ex)) { throw; } } } if (listItems.ListItemCollectionPosition == null) { return; } else { /*if query contains lookup column filter last batch returns null by removing the lookup column in paginginfo query will return next records */ string pagingInfo = listItems.ListItemCollectionPosition.PagingInfo; string[] parameters = pagingInfo.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries); List<string> requiredParameters = new List<string>(); foreach (string str in parameters) { if (str.Contains("Paged=") || str.Contains("p_ID=")) requiredParameters.Add(str); } pagingInfo = string.Join("&", requiredParameters.ToArray()); listItems.ListItemCollectionPosition.PagingInfo = pagingInfo; query.ListItemCollectionPosition = listItems.ListItemCollectionPosition; } } }
public void ProcessListItems(SPList list, SPQuery query, ItemProcessor itemProcessor, ItemProcessorErrorCallout errorCallout) { ProcessListItems(list, query, false, itemProcessor, errorCallout); }
private static void ProcessItem(SPListItem item, bool fIncludeFolderItems, ItemProcessor itemProcessor, ItemProcessorErrorCallout errorCallout) { if (item == null) { throw new ArgumentNullException("item"); } if (itemProcessor == null) { throw new ArgumentNullException("itemProcessor"); } if (fIncludeFolderItems || (item.FileSystemObjectType != SPFileSystemObjectType.Folder)) { try { itemProcessor(item); } catch (System.Exception exception) { if ((errorCallout == null) || errorCallout(item, exception)) { throw; } } } }
public void ProcessItems(SPListItemCollection items, bool fIncludeFolderItems, bool fIterateInReverseOrder, ItemProcessor itemProcessor, ItemProcessorErrorCallout errorCallout) { if (items == null) { throw new ArgumentNullException("items"); } if (itemProcessor == null) { throw new ArgumentNullException("itemProcessor"); } if (fIterateInReverseOrder) { for (int i = items.Count - 1; i >= 0; i--) { ProcessItem(items[i], fIncludeFolderItems, itemProcessor, errorCallout); if (ShouldCancel(IterationGranularity.Item)) { return; } } } else { for (int j = 0; j < items.Count; j++) { ProcessItem(items[j], fIncludeFolderItems, itemProcessor, errorCallout); if (ShouldCancel(IterationGranularity.Item)) { return; } } } }
public void ProcessItems(SPListItemCollection items, bool fIncludeFolderItems, ItemProcessor itemProcessor, ItemProcessorErrorCallout errorCallout) { ProcessItems(items, fIncludeFolderItems, false, itemProcessor, errorCallout); }
public void ProcessListItems(SPList list, SPQuery query, bool fIterateInReverseOrder, ItemProcessor itemProcessor, ItemProcessorErrorCallout errorCallout) { if (list == null) { throw new ArgumentNullException("list"); } if (query == null) { throw new ArgumentNullException("query"); } if (itemProcessor == null) { throw new ArgumentNullException("itemProcessor"); } ProcessListItems(list, query, items => ProcessItems(items, false, fIterateInReverseOrder, itemProcessor, errorCallout), null); }