Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

Event Receiver update document content on ItemUpdating

$
0
0

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 documentbyte[] 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);}


Viewing all articles
Browse latest Browse all 25064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>