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!
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:
Trigger: Start with a trigger that suits your needs, such as "When a file is created or modified" in a SharePoint library.
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"
}
This HTTP request uses the
moveto
method to rename the file, effectively changing its extension[1][2].Here's a more detailed breakdown:
Trigger: Choose a trigger that fits your scenario, such as "When a file is created or modified".
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
, andYourFileName.new
with your actual site name and file names.
Headers: Add the following headers:
{ "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
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!
It is not working anymore. I ended up by creating a new file, setting up the properties and deleting the old one.
Hi,
Is there any solution for changing file extensions?
Thank you
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"
}
]
}
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
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
Maybe you can use the SharePoint API with the Send HTTP Request to SharePoint action.
maybe you can go with that approach
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.
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‘)
stampcoin
97
Michael E. Gernaey
82
Super User 2025 Season 1
David_MA
48
Super User 2025 Season 1