1

In my SPItemEventReceiver I have two methods one ItemCheckedOut and one ItemUpdated.

In the ItemCheckedOut I update one listitem column.

In the other one I do some other updates to the listitem.

When I implemented this ItemCheckedOut I started receive "Save conflict" when I try to publish the item.

The Itemupdated is not even getting trigged.

public override void ItemCheckedOut(SPItemEventProperties properties)
    {
        SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (var site = new SPSite(properties.Web.Site.ID))
                {
                    using (var web = site.OpenWeb(properties.Web.ID))
                    {
                        web.AllowUnsafeUpdates = true;
                        var item = properties.ListItem;
                        EventFiringEnabled = false;
                        item[BuiltInFieldId.Approval] = false;
                        item.Update();
                        web.AllowUnsafeUpdates = false;
                    }
                }
            });

How can I solve this issue?

  • I believe you need to re-enable eventfiringenabled when you are done... – BlueBird May 30 '13 at 13:35
  • I tried that didnt work :( – Rohander May 30 '13 at 13:59
3

I would say reasons might be due to a combination of facts:

you are actually creating a new instance under "System account" - which could practically mean executing in the context of another user. - Use SystemUpdate instead to avoid Version and other automatic column updates - Consider using Synchronous on the receiver declaration (Elements.xml) to avoid additional concerns regarding order of events.

In general, try consolidating changes on the item to avoid triggering multiple Update events, overall re-enable events firing when done.

0

Not sure if this would really work but can you try to initialize a new SPListItem rather than just using the properties.listItem itself? it is just to align with your initialization of the SPSite and SPWeb Object maybe you can do something like

SPListItem item = Properties.ListItem.Parent.GetItemByID(properties.ListItem.ID);

and then do the update in that specific item.

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.