A fast way to update lots of list items is by using the function ProcessBatchData(). This function requires a CAML string that indicates which list items to create or modify. For example the following string creates two announcements (from msdn):
string strPost = “<?xml version=\”1.0\” encoding=\”UTF-8\”?>” +
“<ows:Batch OnError=\”Return\”>” +
“<Method ID=\”A1\”><SetList>” + strGuid + “</SetList>” +
“<SetVar Name=\”ID\”>New</SetVar>” +
“<SetVar Name=\”Cmd\”>Save</SetVar>” +
“<SetVar Name=” +
“\”urn:schemas-microsoft-com:office:office#Title\”>” +
“New Manager</SetVar>” +
“<SetVar Name=” +
“\”urn:schemas-microsoft-com:office:office#Body\”>” +
“Congratulations to Mary for her promotion!</SetVar>” +
“<SetVar Name=” +
“\”urn:schemas-microsoft-com:office:office#Expires\”>” +
“2003-09-14T00:00:00Z</SetVar>” +
“</Method>” +
“<Method ID=\”A2\”>” +
“<SetList>” + strGuid + “</SetList>” +
“<SetVar Name=\”ID\”>New</SetVar>” +
“<SetVar Name=\”Cmd\”>Save</SetVar>” +
“<SetVar Name=” +
“\”urn:schemas-microsoft-com:office:office#Title\”>” +
“New Technical Consultant</SetVar>” +
“<SetVar Name=” +
“\”urn:schemas-microsoft-com:office:office#Body\”>” +
“Welcome to the team, John!</SetVar>” +
“<SetVar Name=” +
“\”urn:schemas-microsoft-com:office:office#Expires\”>” +
“2007-10-15T00:00:00Z</SetVar>” +
“</Method>” +
“</ows:Batch>”;
I have created a webpart that uses the ProcessBatchData() function to update some list items (in a document list) and then perform a checkout on the same list items. The webpart performs these actions in an AJAX UpdatePanel. The default timeout of AJAX is 90 seconds. After 90 seconds a client side JavaScript popup will appear but the webpart seems to continue finishing all actions…
Next the end-user resubmits the request (because he had a timeout error) and the ProcessBatchData() function again updates the list items. When the webpart tries to perform a checkout of the list items an exception is thrown because the items are already checked out.
So far so good.
Now comes the buggy part. All list items that were in the ProcessBatchData() are corrupted! For each list item there are duplicate versions in the version history:
3.0 7-2-2009 9:44 User X 206,6 kB
3.0 7-2-2009 9:48 User X 206,6 kB
2.0 7-2-2009 9:41 User X 206,6 kB
The version 3.0 occurs twice with the older (9:44) on top! SharePoint doesn’t understand this anymore and will throw an exception for each attempt to edit the list item (sorry for the dutch error message):
De URL Tekeningen/mydrawing.dwg is ongeldig. De URL verwijst mogelijk naar een niet-bestaand bestand of niet-bestaande map of verwijst naar een geldig bestand of een geldige map buiten het huidige web.
In the SharePoint content database there is an entry in the AllDocs table and one in the AllDocVersions table, both with version 3.0 or 1536. I don’t like editing the SQL database directly and the only way to correct this problem with a Microsoft supported method is to delete all documents and upload them again…
To show a list with all documents with this problem I used the sql query:
/* select all documents that have duplicate versions */
SELECT AllDocs.LeafName, AllDocVersions.Id, AllDocVersions.Version, AllDocs.UIVersion,
AllDocVersions.Size, AllDocVersions.CheckinComment
FROM AllDocVersions INNER
JOIN
AllDocs ON AllDocVersions.Id = AllDocs.Id
WHERE
(AllDocs.UIVersion = AllDocVersions.Version)
As a workaround I replaced the ProcessBatchData() function with a foreach loop and a ListItem.SystemUpdate() inside the loop. That seemed to solve the issue but it’s a bit slower. But… better slow then sorry.


[...] ProcessBatchData can be buggy February 2009 Possibly related posts: (automatically generated)#1 Page and Top 3 Posts In [...]