質問

Recently I need to take care an SP2010 farm which I am not familiar. There is an event receiver with part of code as below:

SPListItemCollection ListA = properties.Web.Lists["ListA"].Items;
List<int> idList = new List<int>();
foreach (SPListItem item in ListA)
{
        if (Convert.ToString(item["Title"]) == variableA)
           {
            idList.Add(item.ID);
           }
}
foreach (int i in idList)
{
        properties.Web.Lists["listA"].Items.DeleteItemById(i);
}

The problem is right now the "ListA" consist more than 30,000 records and it takes 10 minutes to delete 100 items. Obviously we don't need to loop thru 30,000 records in "ListA".

I cannot find useful sample on web because our server have an old patch level (and we cannot patch for some reason). For example, "using Microsoft.SharePoint.Client.QueryExpression;" return "QueryExpression" not exist in namespace "Microsoft.SharePoint.Client".

Could you advice me how to rewrite with basic namespace like "Microsoft.SharePoint"?

役に立ちましたか?

解決

Look into using the SPWeb.ProcessBatchData.

Here is an answer on a related question - Deleting all the items from a large list in SharePoint

他のヒント

Did you try to select items from list with CAML? This approach should work faster and doesn't need extra packages. This link can help you - http://sharepoint.infoyen.com/2012/04/18/delete-selected-items-from-sharepoint-list-programmatically/

ライセンス: CC-BY-SA帰属
所属していません sharepoint.stackexchange
scroll top