SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What attributes uniquely identify an item in a SharePoint 2010 list? For example, I want to programmatically find all items in a list, given only the URL of the list's location. Then I want to iterate over all of the list's items, creating a "UniqueListItem" object for each item in the list. What properties would that UniqueListItem need, to be able to uniquely identify an item in the list? I think each SP list has a unique list GUID, and then each item within that list has an integer identifying it. Is that correct? And how would I programmatically find those things? Thanks.

share|improve this question
up vote 2 down vote accepted

Get the list. If GetListFromUrl throws an exception the list doesn't exist. If it does, iterate over your SPListItem collection.

SPList list;
try {list = web.GetListFromUrl("http://sharepoint/sites/wea/Lists/TestList"); }
catch { list = null; } //list does not exist

if (list != null)
    SPListItemCollection itemCollection = list.Items;
    foreach (SPListItem item in itemCollection)
        //do something
share|improve this answer
Thanks. Though I believe your code has some typos since you assigned list the value null. – KyleM Jun 10 '11 at 18:28
No. I declared the list, then entered the try catch. As I mentioned in my post, the line list = web.GetListFromUrl("sharepoint/sites/wea/Lists/TestList"); will throw an exception if the list doesn't exist. I'm catching that exception and assigning it a null value. – Tim Gabrhel Jun 10 '11 at 18:29
Ah, my apologies, I see what you did there. Though 'list' will already be null if the GetListFromUrl method throws an exception. – KyleM Jun 10 '11 at 18:31
Marked as correct yet Tim didn't actually answer the question about the primary key of the list item? – Ryan Jun 13 '11 at 10:18
Short of the extra text in the OP, my provided solution does exactly what he asked for. Find a list, given the URL. Then, iterate over each of the list items. – Tim Gabrhel Jun 13 '11 at 12:54

The list can be identified by URL and has a GUID ID.

Items within the list have a unique integer ID, and a GUID UniqueId. The SPList class has both GetItemById and GetItemByUniqueId methods. Given the choice, the normal Int ID is normally used.

share|improve this answer
+1 for being very comprehensive - I didn't know that list items had a GUID as well as the ID. – Ryan Jun 13 '11 at 10:19
+1 for being so thorough. I did notice that when I looked through the SPList class but when I posted this question I didn't know that SPList was used for SP2010. Thanks for responding! – KyleM Jun 13 '11 at 13:43

The SPList object has a GetItemById method

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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