Microsoft Online requires that you use ProcessBatchData if you are adding multiple items within a loop:
Please use ProcessBatchData. It is a good method for processing a lot of commands against a SPList without having to open a SPListItemCollection and pay the penalty of slow performance if the list contains a substantial amount of items. For more details refer SPWeb.ProcessBatchData Method
This requirement changed my code adding multiple items to a Links list from this:
SPList list = web.Lists[listname];
string[] urls = property.Value.Split(";".ToCharArray());
foreach (string url in urls)
{
SPListItem item = list.Items.Add();
item[SPBuiltInFieldId.URL] = GetUrl(web, url);
item.Update();
}
to this:
StringBuilder methodBuilder = new StringBuilder();
string batchFormat = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<ows:Batch OnError=\"Return\">{0}</ows:Batch>";
string methodFormat = "<Method ID=\"{0}\">" +
"<SetList>{1}</SetList>" +
"<SetVar Name=\"Cmd\">Save</SetVar>" +
"<SetVar Name=\"ID\">New</SetVar>" +
"<SetVar Name=\"urn:schemas-microsoft-com:office:office#URL\">{2}</SetVar>" +
"</Method>";
SPList list = web.Lists[listname];
string listGuid = list.ID.ToString();
int i = 0;
string[] urls = property.Value.Split(";".ToCharArray());
foreach (string url in urls)
{
methodBuilder.AppendFormat(methodFormat, ++i, listGuid, GetUrl(web, url));
}
string batch = string.Format(batchFormat, methodBuilder.ToString());
web.ProcessBatchData(batch);
Using ProcessBatchData obviously reduces readability, so (unless required) I would not use it for only a couple items. But it's good to know when wanting to add lots of items (especially in a post back or an -ing event receiver where the user is waiting).