2

I'm trying to update columns of a ListItem in sharepoint using the following code:

ClientContext context = CreateClientContext(_siteUrl);
SP.List list = GetList(listName, context);
Uri baseUri = GetSPBaseURI(context, list);
// Retrieve documents in SharePoint list
ListItemCollection collListItem = list.GetItems(CamlQuery.CreateAllItemsQuery());
context.Load(collListItem);
context.ExecuteQuery();
int count = 0;
Parallel.ForEach(collListItem, new ParallelOptions {MaxDegreeOfParallelism = 4}, () => CreateClientContext(_siteUrl), (item, loop, localContext) =>
     {
           //do some calculations from file contents and update a column
           item["Column name"] = someValue;
           item.Update();
           localContext.ExecuteQuery();
           count++;
           return localContext;
     }, (localContext) => localContext.Dispose());

Based on information from https://stackoverflow.com/questions/19981744/getting-stackoverflow-exception-with-parallel-for-each-is-this-due-to-thread-s.

However, none of the items in the list are being updated on the site. Is my use of ClientContext wrong?

EDIT I have also tried using the single context, but locking the object upon ExecuteQuery but this causes other problems related to file reading. Is it possible to create multiple ClientContexts for a single site?

  • Do you receive any error? ULS Log entries? – BOG Nov 15 '15 at 19:00
  • No, there's nothing obvious in the logs from what I can see – bak202 Nov 16 '15 at 10:29
  • Did you figure out what is happening? – Animesh Feb 2 '18 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.