I have one master list from which I wish to query and create a subset of this in a new custom list. The code I have so far works, but it is extremely slow and occasionally hits the hard limit of the 30 second request time of a sandboxed solution.
The master list contains about 700 items and I will need to copy up to 500 to the subset list.
Is there a more efficient way of running this query? What is the best practice for this sort of task?
string filterQuery = "<Where><Eq><FieldRef Name='milestone' /><Value Type='Text'>4</Value></Eq></Where>";
SPQuery query = new Query();
query.Query = filterQuery;
SPList list = web.Lists["Projects"];
SPListItemCollection collListItemSrc = list.GetItems(query);
SPListItemCollection collListItemDest = web.Lists[documentTitle].Items;
string projectId = "Project name";
foreach (SPListItem oListItemSrc in collListItemSrc)
{
SPListItem oListItemDest = collListItemDest.Add();
oListItemDest["ProjectID"] = projectId;
oListItemDest["ProjectName"] = oListItemSrc["ProjectName"];
oListItemDest["Owner"] = oListItemSrc["Owner"];
oListItemDest["Manager"] = oListItemSrc["Manager"];
oListItemDest["Objective"] = oListItemSrc["Objective"];
oListItemDest["Duration"] = oListItemSrc["Duration"];
oListItemDest["Milestone"] = oListItemSrc["Milestone"];
oListItemDest.Update();
}