Search This Blog

Saturday, April 11, 2015

GetItemById SharePoint list function optimisation

Hello, a little magic for tonight. If you use custom code around your SharePoint, and you wonder why your code is slow on large document libraries , check out this article:

Then search your code to see if you use GetItemById on items collection level. If you do you might accelerate your code 10x times by simply changing it to list level.

Example (red is not optimal code):

SPList _spList = spWeb.Lists.GetList(document.MossDocLibGuid, false);

         ///       SPListItemCollection listItemCollection = _spList.Items;
         ///       SPListItem item = listItemCollection.GetItemById(document.MossDocId);  

SPListItem item = _spList.GetItemById(document.MossDocId);  

No comments: