1

I have a custom list and I have written an itemUpdating event on it. The event sends an email to some users with updated data. When I click on save, the changes are not saved, though i get the email with updated data. This is the error message

Save Conflict Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes.

and this is the tracelogs

SPException: Save Conflict Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes.] Microsoft.SharePoint.WebControls.SaveButton.SaveItem(SPContext itemContext, Boolean uploadMode, String checkInComment) +20559885 Microsoft.SharePoint.WebControls.SaveButton.OnBubbleEvent(Object source, EventArgs e) +1372 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +70 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981

Here is the code for itemUpdating event

public override void ItemUpdating(SPItemEventProperties properties)
    {           
       try
        { 
            this.DisableEventFiring();
            base.ItemUpdating(properties);
            //logic to check the updated properties and send email
         }
 catch (Exception ex)
        {
            SPDiagnosticsService.Local.WriteTrace(0, category, TraceSeverity.Unexpected, "There was an error occured.\n" + ex.Message);
            log.AppendLine("There was an error occured.\n" + ex.Message);
        }
        finally
        {                
            this.EnableEventFiring();
            SPDiagnosticsService.Local.WriteTrace(0, category, TraceSeverity.Verbose, " execution complete for user : " + properties.UserDisplayName);
        }
     }

my feature event receiver

public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {           
            // Get data from a list.
            SPListItemCollection items = listMessages.GetItems(query);
            foreach (SPListItem listItem in items)
            {
                var listNameToAttachEvent = listItem["List"].ToString();
                SPList listToAttachEvent = currentWeb.Lists.TryGetList(listNameToAttachEvent.Trim());
                if (null == listToAttachEvent) continue;

                DeleteEventReceivers(listToAttachEvent, ClassNameForAlert);
                listToAttachEvent.EventReceivers.Add(SPEventReceiverType.ItemAdded, Assembly, ClassNameForAlert);
                listToAttachEvent.EventReceivers.Add(SPEventReceiverType.ItemUpdating, Assembly, ClassNameForAlert);
                listToAttachEvent.Update();
            }


        }
        catch (Exception ex)
        {
            SPDiagnosticsService.Local.WriteTrace(0, category, TraceSeverity.Unexpected,ex.Message);
            SPDiagnosticsService.Local.WriteTrace(0, category, TraceSeverity.Unexpected, ex.StackTrace);
        }
        finally
        {
            if (currentWeb != null)
            {
                currentWeb.Dispose();
            }              
        }

    }
  • Just a note on your code. I would recommend not to use "SPList listToAttachEvent = currentWeb.Lists.TryGetList(listNameToAttachEvent.Trim());". Instead get lists by their URLs. Something like: "var listToAttachEvent = currentWeb.GetList(SPUtility.ConcatUrls(currentWeb.ServerRelativeUrl, "Lists/List"));" because of 2 reasons: 1.TryGetList doesn't throw an exception, instead returns null, which you really don't want to do in your feature receiver and 2.currentWeb.Lists enumerates all lists on the web site (this might not be a problem if you don't have many of them,but still it's a good practice) – Paul Strupeikis Nov 17 '15 at 16:05
1

I cannot see where your code could fail. But this might be happening if you had multiple event receivers attached to the list. You can check by running the following PowerShell commands:

Add-PSSnapin microsoft.sharepoint.powershell
$web = Get-SPWeb http://webapp/sites/site
$list = $web.Lists["List"]
$list.EventReceivers | sort Type | ft Class, Type

If that's the case, then your future receiver code might be failing by adding multiple event receivers or not removing the existing ones before adding new.

  • Thanks Paul.Found out the error. It was because I was updating a list item in the code in finally block. – Deepika Nov 19 '15 at 11:33

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.