0

I have an Microsoft Office 2010 AddIn which imports Data into SharePoint. The tool creates a Dictionary with over 5000 Values. Every Value is a C#-Class with Data and represents a SharePoint List Item. Because there are lookup relationships between almost all Dictionary-Values (ListItems) i use two loops:

  • in the first loop I create the ListItems and write back the generated ListItemIDs into the Dictionary
  • in the second loop I already have IDs for all ListItems and update the Lookups for all theese created ListItems

Is there a way to minimize the number of my queries ( in worst case scenario there are 5000 ExecuteQuery() for the first loop + 5000 for the second).

2

You do not need to perform ExecuteQuery() on every iteration of your loop, each server request can have a 2MB loadsize (depending on your setup). you can add something like this to your loop.

int counter = 0;
foreach(var item in ListItem)
{
   //do stuff

   counter++;
   item.Update();
   if((counter%50) = 0)
   {          
     context.ExecuteQuery();
   }
}

This will send the past 50 updates to the server in one request which will help performance.

1
  • I know this is an old one, but what about the Ids from the created items. Can you retrieve those even if you only do an ExecuteQuery() every 50 loops? How? – Ole Albers Jul 17 '18 at 14:52
1

A little-known and definitely under-used method is SPWeb.ProcessBatchData. Use this to really effectively perform operations in bulk - I still think there's a limit to what can be done at once, but depending on the schema of your lists this could still be the most efficient way (most definitely in terms of requests sent).

2
  • 1
    Thank you James, in this case, my code will run on the client side (MS Visio Client) and I think, I can't use Server Object Model. – user615993 Feb 26 '13 at 6:31
  • you people can transfer 500 data at a time since in caml query we have for operators it is limited to 500 rows – Venkatesh Kumar Balasubramani Jun 30 '15 at 5:34

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.