I want to get a item from a list without loading all the items of the list.
I know I can do it by calling SPList.getElementbyId(myID)
, but if I don't know if this myID exists in the list, how do I verify it?
Yes I could use
SPListItem myItem = myList.Items[myID];
if (myItem == null)
{
// log that we don't have this item
}
However, this way, when I'm calling myList.Items
, all the items of the list are loaded in the in myList
object (and if I have 40,000 items it is realy a performace issue), so I would rather use:
SPListitem myItem = myList.getElementById(myID);
This way I will not call the Items
property and we will no need to load those items.
Now the issue is that the method getElementById
will throw an exception if that ID does notexist in the list. It is not a solution to put it in a try/catch
statment because we might want to verify several houndreds of IDs and handling all ther throws will lead again to a performance issue.
Any ther ideas to check for the existence of a item with a given id?