Skip to content

Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Problems
  • Triggers
  • Application specific solutions
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Resources
Menu

Rename a file in SharePoint with a single Power Automate action

Posted on April 7, 2021February 10, 2022 by Tom

“Why can’t Power Automate rename a file in SharePoint in the same way it can rename a file in OneDrive? It’s one of the most basic operations!”


Power Automate is still missing an action that will allow you to rename a file in SharePoint. You can update all the file properties with the ‘Update file properties’ action, but file name is not one of them.

One solution I’ve seen is to ‘Copy file’ with a new name, and then delete the original one. It’ll achieve the goal, but it’ll create a new file with new ID, new link, and empty version history. I don’t think it’s a good solution.

Another, much better solution is to update the file name with an HTTP request. As already mentioned a few times on this blog, HTTP requests give you much more control. The limitations of the standard Power Automate actions don’t apply to HTTP requests, the only limitation for them is what the SharePoint REST API allows you to do. And it allows you to update the file name.

But even here I’ve seen complicated HTTP requests that I think are quite complex for most users.

The HTTP request doesn’t have to be as complicated, you don’t need a SharePoint consultant to create it for you.

Simple HTTP request

You can use the same HTTP request as when updating a single SharePoint column. If you define the update operation in the ‘Uri’, you don’t need all the headers. And if you use the right operation, you don’t even need such complicated ‘Body’. The request below is all you need to rename a file.

Method: POST

Uri: _api/web/lists/GetByTitle('<LibraryName>')/items(<DocumentID>)/validateUpdateListItem

Body:
{
    "formValues":[
	{
	    "FieldName": "FileLeafRef",
	    "FieldValue": "<NewFileNameWithExtension>"
	}
    ]
}

Why is the “FieldName”: “FileLeafRef” and not “Name”? As already explain in the article on searching files by their name, FileLeafRef represents the file name. It’s an internal column name that’s used in SharePoint for ages, even though it’s not visible anywhere in the properties. Just don’t forget to include also the file extension in the file name.

Power Automate rename file in SharePoint

Summary

Changing file name is a basic operation for every document storage, and it’s strange that Power Automate doesn’t have an action to rename files stored in SharePoint. But as already shown multiple times, there’s a workaround. And the workaround doesn’t have to be complicated, it can be a simple HTTP request. Simple, if you know the ‘Uri’, ‘Body’ and the internal name for the ‘Name’ property…

You can even update the file name without creating a new version of the document with a small addition to the request. But it might get a bit more complicated if you want to update content of an existing file, not just the file name.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

12 thoughts on “Rename a file in SharePoint with a single Power Automate action”

  1. Paul says:
    May 20, 2021 at 10:52 am

    Hi Tom,

    Thanks for your great site.

    Have you ever tried to “send a HTTP request” to update a multi-choice people picker with an individual or even better an O365 group?

    JSON I am trying in a POST:
    {

    “formValues” :
    [
    {
    “FieldName”:”Assigned_x0020_to”,
    “FieldValue”:”O365groupID”
    }
    ],
    “bNewDocumentUpdate”:false
    }

    Kind Regards,
    Paul

    Reply
    1. Tom says:
      May 22, 2021 at 8:44 pm

      Hello Paul,
      Person or Group column needs a specific format for the “FieldValue”: “[{‘Key’:’claimsLogin’}]”. It works for both, users and M365 groups, e.g. to update 1 M365 group and 1 user to item.
      "FieldValue": "[{'Key':'c:0o.c|federateddirectoryclaimprovider|691a0c9d-xxxx-44e8-yyyy-d6df6cd591e8'},{'Key':'i:0#.f|membership|xxx@tomriha.com'}]"

      Reply
  2. Gary says:
    June 24, 2021 at 11:17 pm

    Excellent tutorial. I was struggling with thsi and your approach is simple and straightforward. The vast majority of sites use the create new file with new file name and delete old file process. This makes more sense.

    Reply
  3. Matt Harris says:
    July 15, 2021 at 1:00 pm

    This has got me so close to what I want. Thanks. Trouble isI want to use it to rename item in doc set without changing name of document set. Any ideas?

    Reply
    1. Tom says:
      July 19, 2021 at 2:08 pm

      Hello Matt,
      it’s been a long time since I worked with Document Sets so I’m afraid that I don’t know how to do this.

      Reply
  4. Pingback: How to Work Effectively With SharePoint Documents using Power Automate – Implementing Tae of <T>
  5. Craig says:
    November 26, 2021 at 7:26 am

    Hi Tom,

    Great article, keep up the good work!

    Reply
  6. Monroe Horn says:
    November 27, 2021 at 9:59 pm

    Thanks for this information. However, when I try this solution I keep getting an error that says the following:
    Value cannot be null.
    Parameter name: formValues

    Here is the body of my request:
    {
    “formValues”:[
    {
    “FieldName”: “FileLeafRef”,
    “FieldValue”: “test.pdf”
    }
    ]
    }

    Do you know why this wouldn’t work?

    Thank you very much

    Reply
  7. Monroe Horn says:
    November 27, 2021 at 10:21 pm

    Hello again,

    I got it to work. I had the wrong HTTP request type.

    Reply
  8. Humberto says:
    June 16, 2022 at 5:41 am

    Excellent post. My input, after a couple of hours struggling with default Documents Library, in spanish (can’t confirm that was the issue), would be to target to the guid enpoint as:

    _api/Lists(guid’81c636c1-7a88-4c47-b72d-a29cc6abc595′)/Items(#id#)/validateUpdateListItem,

    already tested and worked like a charm.

    To find out the guid:
    * open the _api/Lists endpoint
    * search an online xml viewer and search for the library name

    Reply
    1. Tom says:
      June 22, 2022 at 8:53 pm

      Hello Humberto,
      thank you for sharing your solution. It can be a problem if you use multiple languages on a SharePoint site and rename a list/library as it’ll rename it only for the specific language, but list guid is always unique no matter what.
      I wrote about it a bit here: https://tomriha.com/use-the-correct-sharepoint-list-name-in-the-power-automate-http-request/

      Reply
  9. Paul says:
    June 24, 2022 at 8:54 am

    Thanks Tom, your solution worked so well!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Now available:

The Ultimate Power Automate expressions cheat sheet
Equip yourself with the tool to translate your thoughts into Power Automate expressions!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Hello and welcome!

My name is Tom and I'm a business process automation consultant and Microsoft MVP living in the Czech Republic. I’ve been working with Microsoft technologies for almost 10 years, currently using mainly Power Automate, SharePoint, Teams, and the other M365 tools.

I believe that everyone can automate part of their work with the Power Automate platform. You can achieve a lot by "clicking" the flows in the designer, but you can achieve much more if you add a bit of coding knowledge. And that's what this blog is about.

To make the step from no-code Power Automate flows to low-code flows: using basic coding knowledge to build more complex yet more efficient flows to automate more of your daily tasks.

  • Check if email already exists in Outlook contacts (Power Automate)August 7, 2022
  • Set permissions for a SharePoint list or library with Power AutomateAugust 3, 2022
  • Handle deleted files in synchronised SP library in Power AutomateJuly 31, 2022
  • Create item with lookup column in a dynamic list (Power Automate)July 27, 2022
  • How to move list between SharePoint tenants with Power AutomateJuly 24, 2022

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

© 2022 Let's POWER Automate | Powered by Superbs Personal Blog theme