The file Document.docx is locked for shared use by user in Power Automate

While working on a document management system, I set up a Power Automate flow to generate a custom ID for every file that gets uploaded. The ID creation worked exactly as expected, but I encountered an issue when attempting to create a document from a template. Power Automate showed an error:

Locked for shared use by user error in Power Automate
Action 'Update_file_properties' failed: The file "https://tenant.sharepoint.com/sites/PowerAutomateTutorial/PDFDocument/Document.docx" is locked for shared use by lidiah@tenant.onmicrosoft.com. clientRequestId: 17dc1e2b-028f-41fb-b123-76086c8bc5fa serviceRequestId: 9738bda1-4av4-0000-e25a-46ea19825feb

In this tutorial, I’ll explain why this error occurs and how you can fix it in a Power Automate flow.

Why does the error “The file is locked for shared use” occur in Power Automate?

When you try to update or modify a document in SharePoint or OneDrive through Power Automate, the system sometimes locks the file temporarily. This happens because:

  • Another user has the document open in a Browser (online or desktop).
  • A background process (like indexing or sync) is still accessing the file.
  • Power Automate itself tries to update the file properties while the document is in use.

Since SharePoint doesn’t allow multiple updates on the same file at the same time, the flow throws the locked for shared use error.

Power Automate document locked for shared use issue

[Solved] file locked for shared use error in Power Automate

In my case, I created a flow that triggers when a file is created in a document library. The flow generates a custom ID using the expression below:

concat('PA-PDF-', formatNumber(triggerBody()?['ID'], '000')) 

This expression returns an ID like PA-PDF-001, PA-PDF-010, PA-PDF-100, etc. After generating the ID, I used the Update file properties action to set this value in the Document ID column.

File locked for shared use error in Power Automate flow

However, this is where the error occurred, because Power Automate was trying to update the file properties immediately after the file was created, while SharePoint was still processing the document.

To fix this issue, you can follow these steps:

  1. Edit that flow and add an Initialize variable action with the following parameters:
    • Name: varFileUnlocked
    • Type: Boolean
    • Value: false
Power Automate Word file locked by another user
  1. Next, click the Initialize variable action and navigate to the settings tab. Under Run after, ensure only “Has failed” is checked.
power Automate file locked for shared use by user
  1. Add a Do until loop and provide the parameters below:
    • Loop until:
@{variables('varFileUnlocked')} is equal to ture 
Locked file error in Power Automate SharePoint flow
  1. Under the do until action, add a Delay action and provide the following parameters:
    • Count: 5
    • Unit: Second
Document locked by user during Power Automate process

Note: For this example, I am taking the second, but it is not a good way.

  1. After that, add the Update file properties action and provide the parameters below:
    • Site Address: Provide the site address where the library is present.
    • Library Name: Select the library name.
    • Id: provide ID from dynamic content when a file is created.
    • Document ID: Provide output of the compose action.
Power Automate cannot access file locked for shared use
  1. Then add a Set variable action and provide the parameters below:
    • Name: varFileUnlocked
    • Value: true
Error message file locked for shared use in Power Automate

Now that our flow is complete, save and test it.

Now go to your document library and upload a new file (you can upload a Word, PDF, or any other document).

File in use locked for shared use Power Automate problem

After a few seconds, refresh the library, and you will notice that the custom Document ID has been created successfully.

Power Automate locked file access denied error

If you check the flow run history in Power Automate, you will see that the Do until loop retried a few times until the file was unlocked. Once the file was free, the Update file properties action ran successfully, and the custom ID was updated in the Document ID column.

Document locked by another user error in Power Automate

The error “The file is locked for shared use” is quite common when working with SharePoint or OneDrive in Power Automate, especially when dealing with templates or recently uploaded files. The file is temporarily locked, which prevents immediate updates.

By using a Do until loop with a small delay, you can wait until the file is unlocked and then update it without errors.

You may also like:

Power Apps functions free pdf

30 Power Apps Functions

This free guide walks you through the 30 most-used Power Apps functions with real business examples, exact syntax, and results you can see.

Download User registration canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App