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:

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.

[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.

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:
- Edit that flow and add an Initialize variable action with the following parameters:
- Name: varFileUnlocked
- Type: Boolean
- Value: false

- Next, click the Initialize variable action and navigate to the settings tab. Under Run after, ensure only “Has failed” is checked.

- Add a Do until loop and provide the parameters below:
- Loop until:
@{variables('varFileUnlocked')} is equal to ture

- Under the do until action, add a Delay action and provide the following parameters:
- Count: 5
- Unit: Second

Note: For this example, I am taking the second, but it is not a good way.
- 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.

- Then add a Set variable action and provide the parameters below:
- Name: varFileUnlocked
- Value: true

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).

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

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.

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:
- Retrieve Specific Item in Power Automate
- Send an Email with Attachments in Power Automate
- Send Email Reminders from a SharePoint List using Power Automate
- Send an Email with Attachments from Local Folder using Power Automate
- Extract Invoice Details From SharePoint Using AI Builder in Power Automate

Hey! I’m Bijay Kumar, founder of SPGuides.com and a Microsoft Business Applications MVP (Power Automate, Power Apps). I launched this site in 2020 because I truly enjoy working with SharePoint, Power Platform, and SharePoint Framework (SPFx), and wanted to share that passion through step-by-step tutorials, guides, and training videos. My mission is to help you learn these technologies so you can utilize SharePoint, enhance productivity, and potentially build business solutions along the way.