Apparently, when you add an item to a list using SPList.Items.Add(…), SharePoint is clever enough to first get all the items in that list and then add the new item. When you need to add a large number of items to a list, this slows down performance. What you need to do is first execute a query saying you need an empty list (RowLimit = 0) and then add your item to it. Then SharePoint will return the List-item with no listItems in it.
1: SPQuery query = new SPQuery {RowLimit = 0};
2: SPListItem newItem = list.GetItems(query).Add();
3: newItem[SPBuiltInFieldId.Title] = DateTime.Now.ToString();
4: newItem.Update();
Many thanks to René Hézser’s blog to pointing this out!
a29b4a1a-b58d-4be2-afe0-a3a9272e75e9|0|.0
Tags: