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 attach a file to the list item when it is updating and when new item added. Additional condition when item updating - if the file already exists, remove it and replace the new one.

I receive events ItemAdded and ItemUpdating. In ItemAdded all is good, but ItemUpdating returns error this 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. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: Microsoft.SharePoint.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. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace: [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) +20032623 Microsoft.SharePoint.WebControls.SaveButton.OnBubbleEvent(Object source, EventArgs e) +1167 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

My code:

// Generate PDF
string pdfPath = GeneratePDF(properties);
FileInfo file = new FileInfo(@"" + pdfPath);

SPListItem attachItem = properties.ListItem;
SPAttachmentCollection attchList = attachItem.Attachments;
int countElem = attchList.Count;
string Resume = "tempdoc.pdf";
bool fileExist = false;
if (countElem > 0)
{
    for (int i = 0; i < countElem; i++)
    {
        string currAttch = attchList[i];
        if (currAttch == Resume)
        {
            attchList.Delete(file.Name);
            fileExist = true;
            break;
        }
    }
}
if (!fileExist)
{
    // attach resume
    attchList.Add(file.Name, addFile(file));
}
this.EventFiringEnabled = false;
attachItem.Web.AllowUnsafeUpdates = true;
attachItem.Update();
//attachItem.SystemUpdate(false);
attachItem.Web.AllowUnsafeUpdates = false;
this.EventFiringEnabled = true;
share|improve this question
    
I see you have a SystemUpdate call there, did you try using just that (with the 'false' argument), and skip the Update call altogether? –  einaros Apr 12 '11 at 12:12

1 Answer 1

What you are doing is something like this:

  • ItemUpdating (attachItem.Update())
  • [internal]SPListItem.Update()

Which causes the internal Update to fail because you have already done it.

Try putting your code in ItemUpdated, rather than ItemUpdating.

The flow is then

  • ItemUpdating
  • [internal]SPListItem.Update()
  • ItemUpdated (attachItem.Update())
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.