My customer has a Page Library with versioning enabled and no versions limit.
There is pages with more than 300.000 versions.
I need to delete all old versions, but keep safe the 5 newer versions.
We have a On-Premises solution. My first try was calling
SPFile.Versions.DeleteAll() with no success after 1 day running it in just one file.
My next try was to limit library versions count to 5 and then running
SPFile.Item.SystemUpdate() having the same result as above.
And then, by last, I created a
TestPage.aspx file with some versions.
I believed that my rescue would be the
SPWeb.ProcessBatchData method and so confident as I could be, I wrote...
<?xml version="1.0" encoding="UTF-8"?> <ows:Batch OnError="Continue"> <Method ID="0,Delete"> <SetList Scope="Request">xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</SetList> <SetVar Name="Cmd"> Delete </SetVar> <SetVar Name="ID"> 21 </SetVar> <SetVar Name="owshiddenversion"> 2 </SetVar> <SetVar Name="owsfileref"> http://customer/Pages/TestPage.aspx </SetVar> </Method> </ows:Batch>
SPWeb.ProcessBatchData method has deleted
TestPage.aspx and all its versions.
What could I do to delete several versions of several files in several lists without taking more than one day per file or loosing all data?
SPWeb.ProcessBatchData is the answer, but I missing something here.