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'm working on a ItemAdded event for a document library, and I'm running into this error in SharePoint 2007...

The file Lists/Shared Audit Documents/1387/Audit Report.docm has been modified by msclistmembershipprovider:afitzpatrick@t on 27 Apr 2012 11:19:31 -0400. 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: System.Runtime.InteropServices.COMException: The file Lists/Shared Audit Documents/1387/Audit Report.docm has been modified by msclistmembershipprovider:afitzpatrick@t on 27 Apr 2012 11:19:31 -0400.

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:

[COMException (0x81020037): The file Lists/Shared Audit Documents/1387/Audit Report.docm has been modified by msclistmembershipprovider:afitzpatrick@t on 27 Apr 2012 11:19:31 -0400.] Microsoft.SharePoint.Library.SPRequestInternalClass.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish) +0
Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish) +203

[SPException: The file Lists/Shared Audit Documents/1387/Audit Report.docm has been modified by msclistmembershipprovider:afitzpatrick@t on 27 Apr 2012 11:19:31 -0400.] Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish) +251
Microsoft.SharePoint.SPListItem.AddOrUpdateItem(Boolean bAdd, Boolean bSystem, Boolean bPreserveItemVersion, Boolean bNoVersion, Boolean bMigration, Boolean bPublish, Boolean bCheckOut, Boolean bCheckin, Guid newGuidOnAdd, Int32& ulID, Object& objAttachmentNames, Object& objAttachmentContents, Boolean suppressAfterEvents) +1026
Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, Boolean bPreserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean bPublish, Boolean bNoVersion, Boolean bCheckOut, Boolean bCheckin, Boolean suppressAfterEvents) +182
Microsoft.SharePoint.SPListItem.UpdateOverwriteVersion() +94
Microsoft.SharePoint.WebControls.SaveButton.SaveItem(SPContext itemContext, Boolean uploadMode, String checkInComment) +215
Microsoft.SharePoint.WebControls.SaveButton.SaveItem() +71
Microsoft.SharePoint.WebControls.SaveButton.OnBubbleEvent(Object source, EventArgs e) +277
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

I basically am taking an uploaded macro-enabled document, copying all the data to a clean template, then using SaveBinary. Code is as follows...

    private void UploadFile(string strNewPath, SPListItem spliItem, Guid gSiteID)
    {
        //string strSiteURL = ConfigurationManager.AppSettings["MSCMail.NewUserLink"];
        string DocumentFileURL = spliItem.Web.Url + '/' + spliItem.Url;

        FileStream fileStream = null;
        Byte[] fileContent = null;
        fileStream = File.OpenRead(strNewPath);
        fileContent = new byte[Convert.ToInt32(fileStream.Length)];
        fileStream.Read(fileContent, 0, Convert.ToInt32(fileStream.Length));
        fileStream.Close();

        SPSite spsMySite = new SPSite(gSiteID);
        SPFile tempFile = spliItem.File;

        spsMySite.AllowUnsafeUpdates = true;
        this.DisableEventFiring();

        tempFile.SaveBinary(fileContent);
        this.EnableEventFiring();

        spsMySite.Dispose();
    }

I hit the error when I click OK on the editform.aspx for the Document Library. Now, I've researched this a bit on the web, and I could move code to a later event, such as ItemUpdated or ItemCheckedIn. There's a couple of other suggestions here http://blogs.msdn.com/b/manuj/archive/2009/09/22/itemadded-event-on-document-library-the-file-has-been-modified-by-on-error.aspx

Any recommendations on the best way to get around this error?

share|improve this question

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.