File Renaming in SharePoint Document Library using Power Automate
I came across a scenario where I needed to update a file’s name which is stored in the SharePoint Document Library. In this process, I realized that the “Update File Properties” action in Power Automate doesn’t offer an option to modify the file name directly.
The Solution: Leveraging the Send an HTTP Request to SharePoint action
So let’s now dive into the steps for executing the file renaming process:
Step 1 : Retrieve the Site URL, Document Library Name, and File ID from SharePoint that you need to rename.
Step 2 : To initiate the Flow, we’re utilizing a Manual trigger for demonstration purposes. In a real-world scenario, this trigger might vary based on the specific business requirements. We’ll need essential values like the Site URL, Document Library Name, and ID Value to accurately identify the file for which we use the initialize variable action.
The File Identifier can be dynamically passed in vDocLibraryFileIdentifier if it’s already available from a prior action or directly from PowerApps. For demonstration purposes, we are currently using a static value of 1 as the Identifier.
Additionally, we use the same initialize variable action to define the new file name. In this step, you have the flexibility to implement logic using expressions to rename the file in alignment with specific business requirements.
Step 3 : Utilize the Send an HTTP Request to SharePoint action, which will be used to rename the file.
In the URI field, input the following value and ensure to substitute the placeholders <vDocumentLibraryName> and <vDocLibraryFileIdentifier> with the respective variables utilized in Step 2.
_api/web/lists/GetByTitle('<vDocumentLibraryName>')/items(<vDocLibraryFileIdentifier>)/validateUpdateListItem
In Our Example
_api/lists/GetByTitle('@{variables('vDocLibraryName')}')/Items(@{variables('vDocLibraryFileIdentifier')})/validateUpdateListItem
Within the Body field, enter the following value, making sure to replace <New File Name.extension>
with your actual new file name.
{
"formValues":[
{
"FieldName": "FileLeafRef",
"FieldValue": "<New File Name.extension>"
}
]
}
In Our Example we use the vNewFileName variable from Step 2
{
"formValues":[
{
"FieldName": "FileLeafRef",
"FieldValue": "@{variables('vNewFileName')}"
}
]
}
Following these steps, you’ll be able to successfully rename files in a SharePoint document library using Power Automate.
Thank you for reading and we hope this blog post was helpful. Stay tuned for more Power Platform tips and tricks!
If you found this useful and would like to connect ! Please feel free to reach out via LinkedIn | Email