I am trying to update a document in the item updating event receiver, but I keep getting the error: "The file IOF/This is a.docx has been modified by ....."

I have the following code in my SP 2013 environment in an event receiver:

public override void ItemUpdating(SPItemEventProperties properties)
        EventFiringEnabled = false;
        properties.List.ParentWeb.AllowUnsafeUpdates = true;

        SPListItem item = GetListItem (properties.ListItem);
        SPFile file = item.File;

        if ((SPFileLevel) Convert.ToInt32( properties.AfterProperties["vti_level"]) == SPFileLevel.Published)
            //Update the published date inside the document
            byte[] contents = file.OpenBinary();
            ISPWorker worker = Worker.GetWorker(file.Name, contents);


        properties.List.ParentWeb.AllowUnsafeUpdates = false;
        EventFiringEnabled = true;

  • Try the same in ItemUpdated event instead of Updating ! – Arsalan Adam Khatri Apr 1 '13 at 13:21
  • I cant use ItemUpdated because by then its check in already and when I edit the document I get an error that the document must first be checked out. – NYTom Apr 1 '13 at 13:21
  • You can checkout/checkin inside your event receiver – lgaud Apr 1 '13 at 15:08
  • 1
    I thought about that but that would mean for every check in the major version would go up by two since Im dealing with published documents. – NYTom Apr 1 '13 at 17:21
  • I tried checking out the file, updating it and then checking it back in in the ItemAdded event but I get the same error. – NYTom Apr 1 '13 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.