Skip to main content

Notifications

Power Automate - Building Flows
Unanswered

change file extension with power automate

Posted on by

Is it possible to change an existing file's extension in a SP document library?  I have seen many example on renaming the file's name but not the actual extension.  For example is a file's name is file.html can i change it to file.aspx without having to create a new file and deleting the old one?  Thanks!

  • SemiAwakeNic Profile Picture
    SemiAwakeNic 2 on at
    change file extension with power automate
    Not sure if it's against the rules to post AI answer, but this answer by Copilot worked for me.
     
     

    You can indeed use HTTP requests in Power Automate to change a file extension on SharePoint. Here's a step-by-step guide on how to do it:

     

    1. Trigger: Start with a trigger that suits your needs, such as "When a file is created or modified" in a SharePoint library.


    2. Send an HTTP request to SharePoint:

       

      • Site Address: Your SharePoint site URL.

      • Method: POST.

      • URI: _api/web/GetFileByServerRelativeUrl('/sites/YourSite/Shared Documents/YourFileName.old')/moveto(newurl='/sites/YourSite/Shared Documents/YourFileName.new',flags=1)

      • Headers:
        json
        {
        "Accept": "application/json;odata=verbose",
        "Content-Type": "application/json;odata=verbose"
        }


    3.  
     

    This HTTP request uses the moveto method to rename the file, effectively changing its extension[1][2].

     

    Here's a more detailed breakdown:

     

    1. Trigger: Choose a trigger that fits your scenario, such as "When a file is created or modified".


    2. Send an HTTP request to SharePoint:

       

      • Site Address: Enter your SharePoint site URL.

      • Method: Select POST.

      • URI: Use the following format:
       
       _api/web/GetFileByServerRelativeUrl('/sites/YourSite/Shared Documents/YourFileName.old')/moveto(newurl='/sites/YourSite/Shared Documents/YourFileName.new',flags=1)
      
       

      Replace YourSite, YourFileName.old, and YourFileName.new with your actual site name and file names.


    3. Headers: Add the following headers:



    4.  
     
       {
         "Accept": "application/json;odata=verbose",
         "Content-Type": "application/json;odata=verbose"
       }
    
     

    This method allows you to rename the file, effectively changing its extension without needing to download and re-upload the file.

     

    Would you like more details on any of these steps or help with setting up the flow?


    References
  • lroade Profile Picture
    lroade 2 on at
    Re: change file extension with power automate

    Hello Spoofan, 

     

    How did you set up the properties? I have deleted the old one and created a new one named .xlsm and it wont open because it says the extension does not match.

     

    Could you send screenshow of your flow? thanks!

     

    2023-05-22_11h21_22.png

  • spoofan Profile Picture
    spoofan 4 on at
    Re: change file extension with power automate

    It is not working anymore. I ended up by creating a new file, setting up the properties and deleting the old one.

  • farsamigmail Profile Picture
    farsamigmail 30 on at
    Re: change file extension with power automate

    Hi,

     

    Is there any solution for changing file extensions?

     

    Thank you

  • Re: change file extension with power automate

    Yes i am passing the filename and extension within the body liek below.  I even tried the new endpoint and it doesnt not change the actual extension.

     

     

    {
    "formValues":[
    {
    "FieldName":"FileLeafRef",
    "FieldValue":"Filename.txt"
    }
    ]
    }

    skarthanal_0-1650638384048.png

     

  • GeorgiosG Profile Picture
    GeorgiosG 1,013 on at
    Re: change file extension with power automate

    Are you also passing in the extensions ? 

    I made a quick research and also found that it Wald solved with another api endpoint, maybe that helps https://powerusers.microsoft.com/t5/General-Power-Automate/Renaming-SharePoint-file-using-REST-API-with-Power-Automate-cuts/td-p/853435

  • Re: change file extension with power automate

    I tried this and got the flow to work however, it is not working as we expect.  If the file already stored in the library is <FileName.aspx> and i want to change it to <NewFile.txt> the flow will run successfully but it only changes the file's name not the extension.  I end up getting NewFile.html

  • GeorgiosG Profile Picture
    GeorgiosG 1,013 on at
    Re: change file extension with power automate

    Maybe you can use the SharePoint API with the Send HTTP Request to SharePoint action.

    maybe you can go with that approach 

     

    B4248E03-8B91-4408-ADF5-533A87846290.jpeg

  • Re: change file extension with power automate

    Thank you your response, I was aware of this but i was looking to retain the document id and not have to create a new one and delete the old file.

  • GeorgiosG Profile Picture
    GeorgiosG 1,013 on at
    Re: change file extension with power automate

    Hi @Anonymous ,

     

    I am not aware of an action for simply changing the file type with one action in Power Automate. you can Create a new file with the content and just pass in file name the new format with a concat() function. You can use directly Name with .xlsx like in my screenshot or use an expression 

    concat(FileName,‘.docx‘)


    CCCD9200-4071-4A16-9A61-029A03430BBD.jpeg

    A57EBFB1-51CC-4BEA-91CB-68210F8093AE.jpeg

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,532

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,050

Leaderboard