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

How to update (not replace) an existing file in Power Automate

Posted on February 17, 2021April 14, 2021 by Tom

“I don’t want Power Automate to replace the existing file, I want to update it. To upload a new version of that file, not to delete the original one.”


When creating, moving or copying file in Power Automate, you might feel limited if you want to update an existing file. ‘Create file’ doesn’t offer any solution, if file with the name already exists, it’ll just fail. ‘Move file’ or ‘Copy file’ will at least offer you some options and not fail right away, but the update is still missing. You can replace (delete) the old file, or you can upload the new file with a different name, ..or fail. But what if you want to keep the file and just update it? To upload a new version of the file?

Power automate move fiel

‘Update file’ action

It’s doable, but it’s not a simple configuration in an action, you must build the functionality by yourself. It’ll require using the ‘Update item’ action to update the file content.

Power Automate update file

‘Update file’ action allows you to update the content of an existing file. You provide the ‘Identifier’ of the file and the new content, and Power Automate will create a new version of that file with the updated content. But it’ll require some preparations in the flow before you can use that action.

Check if file exists

First step is to check if the file already exists. You want to update only existing file, if the file doesn’t exist you can’t update it.

The simplest solution is to use the behaviour mentioned before: if file exists, ‘Create item’ action will fail. And you can configure the same behaviour also for ‘Copy file’ and ‘Move file’ by selecting ‘Fail this action’ if file is already there.

You can use the Create/Copy/Move file action failure as the trigger for the file update section. You’ll set the next action’s ‘Configure run after’ to run only if the previous action ‘has failed’.

Power Automate run after move file failed

Get the existing file ‘Identifier’

Since you need the ‘Identifier’ of the existing file, you must search for it in the destination site/library. ‘Get files (properties only)’ is the action running only if the creation/move/copy failed. Use a filter query to filter by the file name you just tried to use. The output will be an array with a single file.

FileLeafRef eq 'FileNameWithExtension'
Power Automate get file by file name

Get the new file ‘content’

‘Identifier’ of the existing file is only one of the inputs for ‘Update file’ action, the next one is ‘File Content’. Content of the new file that should replace the content of the existing file, which you’ll get with the ‘Get file content’ action. Don’t forget, it must be content of the NEW file.

Update the existing file

Now it’s the time to use the ‘Identifier’ of the existing file and the ‘File Content’ of the new file in the ‘Update file’ action. Don’t worry about the ‘Apply to each’, it’s added because the ‘Get files (properties only)’ action returned an array., but since it’s an array with a single file, it’ll run only once.

Power Automate update existing file

Continue in the flow

This step depends on the design of your flow. If your flow ends with the ‘Update file’ action, you can skip it.

But if your flow should continue, you must use the ‘Configure run after’ once more after the file is updated. The file updating part of the process will run only if there’s an error during creation/move/copy, otherwise it’ll be skipped. In such situations, you must tell the flow where to continue even if the update is skipped. To do that, configure the next action to run also when action ‘is skipped’. It’s similar solution as when you need to disable a part of a flow.

Summary

The solution above is build on two main ideas: first, action ‘failure’ is not always a problem you must solve. In this post you can see that action ‘failure’ can be part of the flow, that you can use it to achieve the goal.

And the second idea: don’t depend only on a single action and its configuration. If some functionality is not available directly, you can probably build it by yourself combining multiple other actions.


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.

11 thoughts on “How to update (not replace) an existing file in Power Automate”

  1. Humphrey Borketey says:
    June 15, 2021 at 3:17 pm

    Hello Tom,
    So I created a similar flow to update the contents of a word file in my SharePoint library. The flow runs successfully but the content of the file does not get updated. Would appreciate some help.
    Thanks

    Reply
    1. Tom says:
      June 16, 2021 at 5:46 pm

      Hello Humphrey,
      I’d check if the flow really went through all the actions or if some were skipped like here: https://tomriha.com/why-has-the-power-automate-condition-grey-colour-in-the-run-history/. Maybe the flow didn’t find the file to update.

      Reply
  2. Krishnamurthy Ramakrishnan says:
    July 29, 2021 at 11:12 am

    How do you get the “Identifier” in the “File to Move” field in the “Move File 2” step before the “Get Properties” step? If I insert the Move File step before the Get Properties step, I cannot get the Identifier. And If I insert it after the Get File Properties and insert “Identifier”, it automatically goes inside an “Apply to Each” and I am unable to move the Move File step to before the Get file (properties only) step.

    Reply
  3. Krishnamurthy Ramakrishnan says:
    July 29, 2021 at 11:15 am

    Sorry, the earlier email id I gave is wrong, I noticed the mistake just as I clicked on “Add Comment”.
    The correct id is ramsabi@gmail.com

    Reply
  4. Krishnamurthy Ramakrishnan says:
    July 29, 2021 at 12:07 pm

    Tom, what is the trigger action for this flow? What are the steps before the “Move File 2” step?

    Reply
    1. Tom says:
      July 29, 2021 at 5:07 pm

      Hello Krishnamurthy,
      the trigger is up to you, it can be ‘When a file is updated’ to synchronise libraries or ‘When an item is modified’ to backup item attachments, it’s not important for the solution.
      The ‘Identifier’ in ‘Move File 2’ is the identifier of the file you want to move, the 1st, original file. The ‘Get file (properties only)’ will give you the ‘Identifier’ of the 2nd file which you can then use to get the content of the new file.

      Reply
  5. Krishnamurthy Ramakrishnan says:
    July 29, 2021 at 6:53 pm

    Thank you for the quick response. I am very new to Power Automate and would be very grateful for your help. How do I get the identifier of the file I want to move – the 1st original file? And why is the Move File showing as “Move File 2”?

    Reply
    1. Tom says:
      July 30, 2021 at 11:10 am

      Take a look on this old article on copying files, that describes a full process, the only difference is that the article uses ‘Copy file’ instead of ‘Move file’.
      It’s called ‘Move File 2’ because the screenshot is only a part of a bigger, more complex process that already had ‘Move File’ action. Since 2 actions can’t have the same name in Power Automate, it automatically added 2 to the 2nd one.

      Reply
  6. Krishnamurthy Ramakrishnan says:
    August 1, 2021 at 5:40 pm

    Hey, Tom thank you for your assistance. I had to bulk upload about 5k revision documents and also update their metadata. This solution of yours gave me the core and I built upon it.
    Thanks again for the help.

    Reply
  7. Andy says:
    December 15, 2021 at 9:21 pm

    My Update File action is failing with the following “A file or folder with the name ‘TestingDoc.docx’ already exists at the destination.”. I didn’t think this was supposed to happen. Help!! 😀

    Reply
    1. Tom says:
      December 16, 2021 at 8:30 am

      Hello Andy,
      that’s fine, that’s the trigger for the updating part of the flow. If you configured it correctly it’ll show this error, but then it’ll continue with the update. But if the flow still ends in an error status, then there’s a problem somewhere later probably.

      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.

  • Format results of date calculation in SharePoint columnJune 29, 2022
  • Why is your Power Automate flow creating duplicatesJune 26, 2022
  • How to create a unique identifier in your Power Automate flowJune 22, 2022
  • How to assign custom SharePoint permission level with Power AutomateJune 19, 2022
  • Remove permissions from a specific SharePoint user with Power AutomateJune 15, 2022

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

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