I have a code in which I have to get the properties of selected item

string ID= QueryString["Id"]//this value is taken from url created dynamically and never be null
SPList list = web.Lists["MyList"];
SPListItem item= list.Items.GetItemById(Convert.ToInt32(ID));

But GetItemById() throws exception that the value doesn't fall in expected range. Please let me now why this happening as the ID is fetch from the item while making the url. Can content DB will help me out in this case?


The above code is working for some items.

  • 1
    I assume it is SharePoint 2013. Does the list contain more than 5000 (i.e. threshold) items? Commented Jan 8, 2015 at 23:12
  • Yes. It contains around 70000 docs
    – nbi
    Commented Jan 9, 2015 at 2:25
  • 1
    Then list.GetItemById(Convert.ToInt32(ID)); should work for you as this doesn't try to enumerate all the items in the list like list.Items.GetItemById(Convert.ToInt32(ID)); does thereby not hitting the thresh hold Commented Jan 9, 2015 at 12:49
  • @PirateEric You hit the bull's eye. Yes that was the culprit. Now using List.GetItemByID() and its working smoothly
    – nbi
    Commented Jan 9, 2015 at 16:57

2 Answers 2


This article says to not use list.Items.GetItemById, but instead to use List.GetItemById(ID). The latter will not enumerate all items in the list. It might not be the source of your issue, but does have a performance impact.

Based on their article, you'd just do SPListItem item= list.GetItemById(Convert.ToInt32(ID));

  • that was typo :P
    – nbi
    Commented Jan 8, 2015 at 17:45
  • Instead of list.Items.GetItemById If I used ListItemCollection.GetItemById() will this make any difference
    – nbi
    Commented Jan 8, 2015 at 17:48
  • Does SPListItem item= list.GetItemById(Convert.ToInt32(ID)); result in the same error? That's what MSDN and the linked article are saying. Commented Jan 8, 2015 at 18:05

You can also use Int32.Parse instead of Convert.ToInt32(ID). I feel the value of ID that you are passing is causing the issue.

Also check the value of the variable ID, whether it is null or not. If it is null then it shall cause issue in getting converted to Int

One of the above should work for you. Give it a try and let me know.

  • thanks Mancy for the infomration, but as I said the ID can not be null and there is no problem in parsing through Convert.ToInt32()
    – nbi
    Commented Jan 9, 2015 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.