/// <returns>A Batch XAML element.</returns>
public static XmlElement CreateBatch(XmlDocument xmlDoc) {
XmlElement elementBatch = xmlDoc.CreateElement("Batch");
elementBatch.SetAttribute("OnError", "Continue");
return elementBatch;
}
/// <summary>
/// Adds a CAML Delete command to a batch for each list item in a given list.
/// </summary>
/// <param name="listService">
/// Required to retrieve all list items in order to create
/// each delete command.</param>
/// <param name="strItemList">The list to delete all list items from.</param>
/// <param name="xmlDoc">The XML document to store the delete commands
in.</param>
/// <param name="elementBatch">
/// An XML element into which which this method will add delete 'Method' ele-
ments.
/// </param>
public static void AddDeleteAllItemsBatch(
Lists listService,
string strItemList,
XmlDocument xmlDoc,
XmlElement elementBatch
) {
// get all items
XmlNode nodeListItems = GetAllListItems(listService, strItemList);
// for each item
XmlNode nodeRsData = nodeListItems.ChildNodes[1];
foreach (XmlNode nodeRow in nodeRsData.ChildNodes) {
if (nodeRow.NodeType == XmlNodeType.Element) {
string strId = nodeRow.Attributes["ows_ID"].Value;
// create a "delete" method
XmlElement elementMethod = CreateMethod(
xmlDoc, elementBatch, "Delete", strId);
// tell the delete method to delete the current report term evaluation
AppendField(xmlDoc, elementMethod, "ID", strId);
}
}
}
/// <summary>
/// Breaks a larg CAML query into smaller batches to avoid the error "Some part
/// of your SQL statement is nested too deeply. Rewrite the query or break it
/// up into smaller queries."
/// </summary>
/// <param name="listService">The SharePoint list service to
32
Putting SharePoint to Work for You, an Internet.com Developer eBook. Copyright 2008, Jupitermedia Corp.
Putting SharePoint to Work for You
[
]