2

I have an issue with updating an item in ItemUpdated event.

Basically on ItemUpdated, I would like to reupdate that item by setting some properties, because it is a docx I have to do it in ItemUpdated.

BUT I get an error which says the following:

{"The file test.docx has been modified by user on "}

I have this code, which trows this error:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
     using (SPWeb web = properties.OpenWeb())
     {
         var list = web.Lists[properties.ListTitle];
         SPListItem listItem = list.GetItemById(properties.ListItem.ID);
         listItem[lookUpFieldName] = "some value";
         listItem.SystemUpdate(false);
     }
});

I thought that open a new instance of SPWeb with this item would solve the problem, but it didn't. Anyone has any diea?

3

Since you are trying to update item on ItemUpdated event you will get this error because another Update event was already in progress so you need to turn off EventFiring before calling SystemUpdate().

Example:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
     using (SPWeb web = properties.OpenWeb())
     {
         var list = web.Lists[properties.ListTitle];
         SPListItem listItem = list.GetItemById(properties.ListItem.ID);
         listItem[lookUpFieldName] = "some value";
         this.EventFiringEnabled = false;
         listItem.SystemUpdate(false);
         this.EventFiringEnabled = true;
     }
});
| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.