Below is the Code to Delete List Item used by Microsoft Sample
spListCollection = spWeb.Lists["ActualAmounttrack"].Items; int itemCount = spListCollection.Count;
for (int k = 0; k < itemCount; k++)
{
SPListItem item = spListCollection[k];
if (IdeaId == item["Title"].ToString())
{
spListCollection.Delete(k);
}
}
Its not Working.
Why the above code is not working - If you need to loop through the ListItemCollection to delete multiple ListItems, your code will not work. When you attempt to delete the last ListItem, you will receive a boundary exceeded exception.
The index to the ListItemCollection should always = 0.
Solution:
Working code
spListCollection = spWeb.Lists["ActualAmounttrack"].Items;
int itemCount = spListCollection.Count;
for (int k = itemCount; k > 0; k - -)
{
int id = k - 1; SPListItem item = spListCollection[id];
if (IdeaId == item["Title"].ToString())
{ spListCollection.Delete(id); }
}
Showing posts with label MOSS. Show all posts
Showing posts with label MOSS. Show all posts
Monday, July 27, 2009
Subscribe to:
Posts (Atom)