Tuesday, June 30, 2009

How to MASS remove item in list

The typical answer is to do a looping to remove all items one by one. This required multiple call to the server. Check out the following approach


private static StringBuilder BatchDeleteCommand(SPList spList)
{
StringBuilder sbDelete = new StringBuilder();
sbDelete.Append("< ? xml version=\ "1.0\" encoding=\"UTF-8\"?>");
string command = "" + spList.ID +
"< / SetList>{0}< / SetVar>Delete< / SetVar>< / Method >";

foreach (SPListItem item in spList.Items)
{
sbDelete.Append(string.Format(command, item.ID.ToString()));
}
sbDelete.Append("
");
return sbDelete;
}

No comments:

Post a Comment