Sharepoint 2010: Deleting all items in SPListItemCollection
SPListItemCollection objlstCollection = list.GetItems(qry);
for (int i = 0; i < objlstCollection.Count; i++)
{
listCollection.Delete(i);
}
Above is the code that I initially wrote to delete the items in the list item collection and that was actually a very silly code. Since once I delete first item in the list the count of the list collection decreased.
So to resolve this problem I wrote the following code.
SPListItemCollection listCollection = list.GetItems(spQuery);
int countItem = listCollection.Count;
for (int i = 0; i < countItem; i++)
{
listCollection.Delete(0);
}
Reference
http://martinlangrock.blogspot.com/2012/05/delete-items-from-splistitemcollection.html
This is EXACT same code as posted at link below 7 months before your post. You should give credit to him for reposting his code.
ReplyDeletehttp://martinlangrock.blogspot.com/2012/05/delete-items-from-splistitemcollection.html
You are right...This blog has been a dumping backyard for long time. I did not care about that.Thanks for the feed back. Reference added!
ReplyDeleteI was suggested this blog by my cousin. I'm no longer positive whether or not this publish is written by him as nobody else realize such special approximately my problem. You are wonderful! Thank you! Useful link: How To Lock Files Business Using Your Childhood Memories.
ReplyDelete