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 / How to Replace an Exis...
Power Automate
Suggested Answer

How to Replace an Existing SharePoint File via Power Automate Using PowerApps ?

(0) ShareShare
ReportReport
Posted on by
 

Hi everyone,

I'm working on a project where I need to replace an existing file in a SharePoint library. The file to be replaced is selected using a PowerApps app, which returns the name of the file. I'm looking to automate this process using Power Automate, but I'm unsure of the best approach and actions to use.

Here are the details:

  • PowerApps: The app allows users to select a file from the SharePoint library and returns the name of the file that needs to be replaced.
  • Requirement: If the file exists in the SharePoint library, replace it with a new version (I need help for this). If it doesn't exist, create a new file (I already made this part)
  • Desired Behavior: I would like to use a similar behavior to the "Replace" button in SharePoint, which replaces an existing file when you upload a new file with the same name. It will not erase all version history.

Could anyone  guide me on the actions and logic needed in Power Automate to achieve this? Any examples or detailed steps would be greatly appreciated.

Thank you in advance for your help!

 
 
 
 
 
Categories:
I have the same question (2)
  • Suggested answer
    AnthonyAmador Profile Picture
    2,553 Moderator on at
    Hi,

    Only the ‘Copy File’ and ‘Move File’ actions in the SharePoint connector contain the option ‘If another file is already there’. Therefore, you would have to create the logic for that. Since you already have the name of the file, you can use the ‘Get Files (Properties Only)’ action to get all the files in the folder, then compare against the name you have from Power Apps. If the file is there, then delete it and create a new one with the content from Power Apps.

    It should look like this.
     


    Hope this helps.
    Anthony. 
     
    If my reply answers your question, please like and mark it as verified. This helps me stay motivated to assist others and makes it easier for users with similar questions to find the answer. Thanks!
    Feel free to connect with me on LinkedIn!
     
  • Suggested answer
    Greatmohan1 Profile Picture
    2 on at
    Hi,
     
    I'm not expert but I have found this to be a really challenging issue, especially if you need to maintain a unique Link (e.g. if you have Unique Document ID turned on), and if you want to maintain the document metadata. 
     
    In my solution, I am using a Powerapp to provide a document management function using Sharepoint document libraries and had to use several flows to get it working.
     
    I didn't find the answer in any one forum, but have managed to cobble together a working process so thought I'd share it:
     
    1. Change the file name in Sharepoint 
     
    You can only effectively replace a file if the file name is identical. If you try to upload a file with a different name, it will create a separate file rather than replacing the one you want to change. If you delete the file and create a new one, then the old ID and metadata are lost...
     
    If the file you want to upload has a different filename (e.g. if original file is Filename1 v1.pdf and the new file is Filename v2.pdf), you will need to change the file name first. 
     
    To do that, I first used Matthew Devaney's smart suggestion for how to create a blank attachments card which you can use to select a file to upload in to the app: https://www.matthewdevaney.com/power-apps-easiest-way-to-upload-files-to-a-sharepoint-document-library/
     
    I then set a check to see if the uploaded file name matched the existing file name.
     
    If the name is different then I used a flow to change the file name. See Sumit Kanchan's helpful guide for details: https://www.sharepointwidgets.com/2022/08/power-automate-rename-file-in.html
     
    NB: I had to use a 4 second timer and a 'pls wait' message before refreshing the data source so that the app would know that the two now had the same name.
     
    2. Upload the file
     
    Once the file names matched, then I went back to Matthew's guide to creating the flow to upload the file.
     
    There was one additional thing I needed to do. M365 Tech help's youtube video gave me the answer: https://www.youtube.com/watch?v=9kIydG85Pcc
     
    You need to disable the content transfer slider on the 'create file' step of your flow to enable overwrite of an existing file.
     
     
    Hey presto - you have now got a new file with the same meta data and the same document ID link. NB: If using Document ID - There is a delay of about 5-10 minutes for the Document ID link to update. You will see a '404 error' if you try to use the link before the update is complete. I had to add a user message to this effect.
     
    Hope that helps,
    Jem
     
     

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 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard