Adding new Item into SharePoint List – Avoid the memory leakage
Never use SPList.Items.Add because this approach gets all items in the list before adding a new SPListItem. Use the following method instead, which does not preload the list items:
private SPListItem OptimizedAddItem(SPList list)
{
const string EmptyQuery = "0";
SPQuery q = new SPQuery {Query = EmptyQuery};
return list.GetItems(q).Add();
}
Thanks ROB GARRETT for this trick
http://blog.robgarrett.com/2009/02/25/efficient-way-to-add-a-new-item-to-a-sharepoint-list/
Comments
Post a Comment