0

I'm trying to update an item when it is added to a document library. I have an EventReceiver on my document library and I am using the ItemAdded event. I am using the New Document button to create a Word doc.

I click save in word, and after the save is complete, my ItemAdded event triggers and runs the following.

listItem["Field"] = value;
listItem.SystemUpdate(false);

I get an error message stating: The file <url> is locked for share use by <user>.

This lock seems to persist until the file is closed in Word.

I found SPLockType in the MSDN which states.

The file is locked for editing by one or more users. Any of these users can save the file if the correct lock identifier is specified. Other users are prevented from saving the file until the lock is released.

Which makes me think I should be able to do this if I can specify the lock id, but I don't know how to do that.

Otherwise, is there a way to delay my code from running until the lock is released? I don't see any methods on SPItemEventReceiver that appear to apply.

  • Do you have already a solution for this problem because I have the same problem. I think it maybe can be something with run with elevated priveliges to solve it but i'm not sure. – deefken Apr 7 '14 at 5:52
  • I don't remember which solution I ended up using and I don't have access to the code anymore. However, a SPD Workflow will wait until the lock is released to run, or the logic can be moved to the ItemUpdated event, which is triggered after the lock is released. – cadrell0 Apr 7 '14 at 14:18
0

listItem.SystemUpdate(false) is supposed to not observe 'Locked' state introduced by Microsoft Office Word.

There is no specific time to wait until lock is released as it can be automatically extended. More detailed post explains the difference between 'Checked Out' / 'Locked' and the reason for both.

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.