locked
The file is checked out or locked for editing by another user System.Runtime.InteropServices.COMException (0x81020036) RRS feed

  • Question

  • Hi all,

    I had implemented one timer job and this job updated status of one of my custom feild  like Document Status.

    Splist item;

    item.update();

    when i run my job then it gives error like :


    Microsoft.SharePoint.SPException: The file URL is checked out or locked for editing by JTC\zuraini. ---> System.Runtime.InteropServices.COMException (0x81020036): The file "~/CustLeaseMgmt/LeaseTenMgmt/Pages/AmenitySaleProgrammeForSittingTenants.aspx" is checked out or locked for editing by USER Name.
       at 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)
       at 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)

    I can't find any related solution.

    Thanks,

    Chandresh.

     

     

     

    Tuesday, May 11, 2010 7:27 AM

Answers

  • It's the normal behavior. You can't update the fields while the file is checked out by another user. 

    You can try to verify if another user has a lock on the file before attempting to update it. Note: I haven't tested it.

    using (SPSite spSite = new SPSite(siteUrl))
    using (SPWeb spWeb = spSite.OpenWeb())
    {
     spWeb.AllowUnsafeUpdates = true;
    
     SPFile spFile = spWeb.GetFile(fileGuid);
         
     if(spFile.CheckOutStatus == SPFile.SPCheckOutStatus.None || (spFile.CheckedOutBy != null && spFile.CheckedOutBy == spWeb.CurrentUser))
     {     
      //update metadata here
      spFile.Item.SystemUpdate(false);
     }
    
     spWeb.AllowUnsafeUpdates = false;
    }
    
    

     

    Wednesday, May 12, 2010 1:46 AM