Sample Code Snippet:
for (int itemCount = 0; itemCount < 100;s itemCount++)
{
SPListItem newItem = listItemCollection.Add();
newItem.Update();
}
Using Batch Update:
ProcessBatchData method takes XML format as input and it will directly communicate with SharePoint content database.
StringBuilder query = new StringBuilder();
query.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");
for (int itemCount = 0; itemCount < 100; itemCount++)
{
query.AppendFormat("<Method ID=\"{0}\">" +
"<SetList>{1}</SetList>" +
"<SetVar Name=\"ID\">New</SetVar>" +
"<SetVar Name=\"Cmd\">Save</SetVar>" +
"<SetVar Name=\"{3}Title\">{2}</SetVar>" +
"</Method>", i, listGuid, someValue, "urn:schemas-microsoft-com:office:office#");
}
query.Append("</Batch>");
spWeb.ProcessBatchData(query.ToString());
Conclusion:
If you have to update a larger number of items its highly recommended to not use the Update method on every item. Instead – use the batch update function ProcessBatchData provided by SPWeb.
Reference Links:
No comments:
Post a Comment