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 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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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;
     }
});
share|improve this answer

Your Answer

 
discard

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

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