문제

I have created one application for deleting Duplicate SPListItem. The list has thousands of duplicate records. While deleting the item (say, approx. after 1000 records deletion). The Application completing the deletion process and showing the successfully completed message. I am appending My code snippet for deleting the items .

spFormIDCollection = spHistoryList.GetItems(query);
                            if (spFormIDCollection != null && spFormIDCollection.Count > 0)
                                for (int i = 0; i < spFormIDCollection.Count - 1; i++)
                                {
                                    SPListItem listItem = spFormIDCollection[i];
                                    if (listItem != null)
                                        if (Convert.ToString(listItem[Common.NotificationDate]).Equals(Convert.ToString(spFormIDCollection[i + 1][Common.NotificationDate])))
                                            listItem.Delete();

                                }

I don't know what went wrong with my code. Can you please explain, if there is any incorrect code. Thanks in advance..

도움이 되었습니까?

해결책

You should change your for-loop to

for (int i = spFormIDCollection.Count - 1; i > -1; i--)

When deleting items the collection.Count decreases and your loop will finish to early.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top