How to get a SharePoint List Item By Unique Id

Warlock picture Warlock · Dec 19, 2012 · Viewed 26k times · Source

Is it possible to get SP List Item by unique Id (without writing a Caml request) if I know a related List Id.

var item = list.GetItemById("CFA9E204-6509-424B-A246-0DE5295C42B2");

When I tried to get item using this code, I received an error: "Input string was not in a correct format."

What's wrong with the GetItemById() method?

Why does it has an overloaded method GetItemById() with a string argument if it understands only integer Id?

EDIT:

I use SharePoint Client Object Model where List entity has no a method GetItemByUniqueId(), but it has the GetItemById() method, which receives string or integer Id.

MSDN Documentation

Answer

Manish picture Manish · Dec 19, 2012

Try this:

SPListItem item = list.GetItemByUniqueId(new Guid("CFA9E204-6509-424B-A246-0DE5295C42B2"));