First published on TECHNET on Jun 27, 2013
This post is a contribution from Charls Tom Jacob, an engineer with the SharePoint Developer Support team.
You have a SharePoint library in which “Require documents to be checked out before they can be edited?” is set to Yes. You have a WorkflowStarting event receiver associated to the list, with the following very basic implementation:
When the event receiver is triggered, the above code will fail with the following exception while getting the item:
When “Require documents to be checked out before they can be edited?” is set to Yes , the uploaded item gets exclusively checked out to the user who uploaded it. This means item won’t be viewable/accessible to ANY other user. This is because the workflow starting event is triggered way before the upload process is fully complete . When “Require documents to be checked out ” is Yes, user is presented with an additional page which says “The document was uploaded successfully and is checked out to you. Check that the fields below are correct and that all required fields are filled out. The file will not be accessible to other users until you check in.”
Event receiver executes while the user is presented with this popup screen, and it executes in the context of SHAREPOINT\SYSTEM account and runs into this error.
|NOTE : Exclusive checkout applies to another scenario, where the user uploads the document but cancels the check-in popup; The document remains checked out and accessible only to the same user.|
Solution: Impersonate the user account while accessing the list item.
With the above code, item is accessed using the same user account which was used to upload the document, hence the code succeeds in getting the item.
Hope this information was helpful!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.