web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / PA flow to rename shar...
Power Automate
Answered

PA flow to rename sharepoint file

(1) ShareShare
ReportReport
Posted on by 30
I have a flow built that pulls data from a Sharepoint list, and creates an Excel file in the SP library.   The SP list includes a "file name" column, that is determined by concatenating text from other columns.  So, if the "name" is Smith, and the "Type" is FML, the file name would be Smith-FML.xlsx
 
I want to create another flow that will rename the file if one of these columns is changed within SP.  So, if the Type in the above record is changed to FMX, the existing Smith-FML.xlsx file would be renamed to Smith-FMX.xlsx.
 
I've been able to get as far as a "When an item or file is modified" trigger, and a "get changes for an item or file (properties only)", but I'm not sure how to proceed from there.  I found a "move or rename a file" action -- but that's under the OneDrive category, not Sharepoint.  I'm also not sure how to reference the "Old" file name, which is of course needed so that the flow knows which file to rename.
 
Thanks for any assistance!
Categories:
I have the same question (0)
  • lbendlin Profile Picture
    8,479 Super User 2025 Season 2 on at
     but that's under the OneDrive category, not Sharepoint. 
    Consider these to be the same thing. You can access OneDrive as if it were a SharePoint Folder.
  • Micky Profile Picture
    365 Moderator on at
    Hi,
     
    You can use Send an HTTP request to SharePoint like the example below.
     
     
    To achieve this follow the steps below.
     
    1. Get the SharePoint Site URL where the file is located
    2. Get the Document Library ID where the file is located
    2.1 You can get the Document library id by going to your site content, clicking on the document library ellipses, and select settings, you should be able to see the id in the URL like the image below.

    3. Get the List Item Entity Type Full Name of the Document Library
    3.1 You can get this by using this Rest API
    3.2 Type this in your browser URL and don't forget to change it to your tenant https://yourtenant.sharepoint.com/_api/web/lists/getbyid('DOCUMENT LIBRARY ID')
    3.3 Search for ListItemEntityTypeFullName like the image below

    4. Get the ID of the file you want to change the name
     
    Now it's time to build the action parameters using the data the information that we previously gathered.
     
    Site Address: VALUE FROM STEP 1
    Method: POST
    Uri/_api/web/lists/getbyId('VALUE FROM STEP 2')/items(VALUE FROM STEP 4)
    Header: Content-Type = application/json;odata=verbose
                  IF-MATCH = *
                  X-HTTP-METHOD = MERGE
    Body{'__metadata': {'type' : 'VALUE FROM STEP 3'
    },'FileLeafRef': 'NEW FILE NAME AND IT'S FILE EXTENSION' }
     
     
    IMPORTANT: Don't miss a single quote!! 
     
    Happy Power Automating :) 
     
     
     
  • richzip Profile Picture
    30 on at
    @Micky  Thank you for the reply.  This is new to me, so I have some additional questions:
     
    For step 3, I assume the "DOCUMENT LIBRARY ID" that I enter is what was provided in step 2; and that I should include both the parentheses and the single quote?  When I entered it this way,  it returned an error of 
     
    "<m:code>-2130575322, Microsoft.SharePoint.SPException</m:code>
    <m:message xml:lang="en-US">List does not exist. The page you selected contains a list that does not exist. It may have been deleted by another user.</m:message>
    </m:error>"
     
    For step 4, how do I obtain the ID of the file whose name I want to change?
  • Verified answer
    trice602 Profile Picture
    15,404 Super User 2025 Season 2 on at
    Hi,
     
    This works in testing and I wanted to share it with you.  So here, in the list if you change the Code column to FAB, the file is successfully updated in your library
     

     
     

     

    Next I am tracking changes and referencing the trigger ID and Since is WindowsStart dynamic content, shown below.




    In my condition, I am checking if the Column Code has changed (or is true) and if so, then do the update to the item and the file name.



     
    The Get Items action has a filter query expression to only get the single file, shown below.  Make sure your data after eq is inside ''.
     

     
     
    Next I am adding two http requests, the second one first if that is helpful.
     
    In the URI the dynamic content is from the Get Items and is the ID.
     
    Note the header items to add.
     
    Here's the body:
     
    {'__metadata':
    {'type':'@{outputs('Send_an_HTTP_request_to_SharePoint_1')?['body']?['d']?['ListItemEntityTypeFullName']}'},
    'FileLeafRef':'Title-Code.xlsx'} <---- dynamic content shown below
     

     

    Here's the top HTTP request

     


     

    The last action is to update the item's column "WorkbookName" with the new file name.  You can't make this is a calculated column by just concatenating Title and Code because at the top of the flow, we use this column to refer to the current file name in Get Items (so we only update it at the end of the flow with the NEW file name).


    Here's the concat expression:


    concat(triggerBody()?['Title'],'-',triggerBody()?['Code'])

     


     

    The http request actions are a little difficult to get right on first try but works well in testing and will be dependable for you.

    ------------------------------------------------

     

     

    ⭐ If this was helpful, please like and mark as a verified answer to help others find this too!

     

     

    Always glad to help! 💯💯💯💯💯

     

    Tom

     

    Follow me on LinkedIn - Thomas Rice, PMP | LinkedIn

  • trice602 Profile Picture
    15,404 Super User 2025 Season 2 on at

    Hi,

    I noticed there was an issue in the previous post that I have corrected.  This version is better and uses Get Changes looking at the Code column directly.  This does mean that it will fire a second time after you update column for the new file name but runs one action and is in milliseconds.

    ------------------------------------------------

     

     

    ⭐ If this was helpful, please like and mark as a verified answer to help others find this too!

     

     

    Always glad to help! 💯💯💯💯💯

     

    Tom

     

    Follow me on LinkedIn - Thomas Rice, PMP | LinkedIn

  • richzip Profile Picture
    30 on at
    @trice602  Thank you very much for your reply!  This seems to make sense to me (mostly).  However, I am getting an error in the "Get files (properties only)" action.  The files to be edited are actually within a subfolder, so I updated the Filter Query to include that.  When running the flow, it returns the error shown below.   (Side note:  do I also need to account for the folders in the "Send HTTP" request actions?
     
    Thank you!
     
     
     
     
     
  • richzip Profile Picture
    30 on at
    @trice602  You can ignore my questions below -- I figured it out, and it works perfectly!  Thank you!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 519 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 296 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard