Some days ago I had a problem to delete all items from standard SharePoint list. There are the following possible ways to do it:
Usage example: clearlist.exe -listUrl http://localhost/sites/project/Lists/Classes/AllItems.aspx -threadCount 10
Link to download Visual Studio Solution
- Delete list at all and create it once again. This option is very fast but we need to create the list again with all fields, views etc. It is a rounite operation and could take much time. Also it can be item event receiver for delete action that makes some changes. The delete list operation without delete all items may cause some problems depending on the logic in the receiver.
- Select all list items and delete it.
for (int i = 0; i < threadCount; i++) { var itemIds = new List<Guid>(); if (i != threadCount - 1) { itemIds.AddRange( (from SPListItem item in items select item.UniqueId) .Skip(i * batchCount).Take(batchCount));
} else { itemIds.AddRange( (from SPListItem item in items select item.UniqueId) .Skip(i * batchCount));
}
ThreadPool.QueueUserWorkItem(DeleteAllItems,
new ThreadParams {Event = events[i], ItemsIds = itemIds});
}
WaitHandle.WaitAll(events);
The application has 2 required parameters: listUrl and threadCount.
Usage example: clearlist.exe -listUrl http://localhost/sites/project/Lists/Classes/AllItems.aspx -threadCount 10
Link to download Visual Studio Solution
Nice post. It works on my doc library
ReplyDeleteWorks perfectly. Thank you very much
ReplyDelete