SPC050223: Do not call SPList.Items.GetItemById()

Do not call SPList.Items.GetItemById(). Use SPList.GetItemById instead.

TypeName: DoNotUseListItemsGetItemById
CheckId: SPC050223
Severity: CriticalWarning
Type: AssemblyFileReference
Resolution

Replace calls to SPList.Items.GetItemById() with SPList.GetItemById().

Bad Practice:

SPWeb myWeb = SPContext.Current.Web;
SPList myList = myWeb.Lists["Tasks"];
SPItem firstItem = myList.Items.GetItemById(0);
Good Practice:
SPWeb myWeb = SPContext.Current.Web;
SPList myList = myWeb.Lists["Tasks"];
SPItem firstItem = myList.GetItemById(0);

Links

comments powered by Disqus