Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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);

            file.SaveBinary(worker.UpdateRevisionDate(DateTime.Now.ToString("MM/dd/yyyy")));
            file.Update();
            item.SystemUpdate(false);
        }

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

        base.ItemUpdating(properties);
    }
share|improve this question
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.