4

I need to update SPListItem using web.ProcessBatchData without create new version.

I've tried to use this xml:

<?xml version="1.0" encoding="UTF-8"?> 
<ows:Batch OnError="Continue"> 
  <Method ID="1"> 
    <SetList>{some-guid}</SetList> 
    <SetVar Name="Cmd">Save</SetVar> 
    <SetVar Name="ID">{list-item-id}</SetVar> 
    <SetVar Name="owshiddenversion">{current-item-version}</SetVar> 
    <SetVar Name="urn:schemas-microsoft-com:office:office#Title">some title</SetVar> 
  </Method> 
</ows:Batch>

After execution of BatchData on this xml i've received new version ({previous-version} + 1) even without changing any visible item fields.

Is it possible to use ProcessBatchData in the same way as SystemUpdate(false)?

P.S. I need to update List item. Previous mentioned xml works perfectly on updating DocumentLibrary items...

Ievhen
  • 41
  • 4

1 Answers1

0

Piece of cake :) lol

 using (var disabler = new DisabledEventFiringScope())
    {
        web.ProcessBatchData(batchXml);
    }

And here is the code for the DisabledEventFiringScope class:

class DisabledEventFiringScope : SPEventReceiverBase, IDisposable
{
    public DisabledEventFiringScope()
    {
        EventFiringEnabled = false;
    }

    public void Dispose()
    {
        EventFiringEnabled = true;
    }
}
Luis Valencia
  • 32,619
  • 93
  • 286
  • 506
  • I made some test and explore that problem on other discussion boards ( http://social.technet.microsoft.com/Forums/sharepoint/en-US/80748556-fed3-4906-a4da-7483d37525d7/cannot-use-processbatchdata-without-increasing-version-of-processed-item ) and yours solution disables only event recivers firing. After executing batch data update version is incremented. – marcinn Jul 15 '13 at 08:18
  • I must downvote your answer, Iwrote unit test on my custom list and it is not working - version is incremented. – marcinn Jul 16 '13 at 12:22
  • I have to flag your comment because it works, you have to build your xml in the right manner. http://stefan-stanev-sharepoint-blog.blogspot.be/2009/07/tips-for-using-spwebprocessbatchdata.html read Using the owshiddenversion field: – Luis Valencia Jul 16 '13 at 13:33
  • BatchDataProcessor wrapps xml creation logic to use with ProcessBatchData method. – marcinn Jul 17 '13 at 16:00