Skip to main content

Notifications

Community site session details

Community site session details

Session Id : X6EL6iZ72nmxEAcGQSKdL1
Power Automate - Building Flows
Unanswered

Overwrite file if it already exist

Like (1) ShareShare
ReportReport
Posted on 1 Feb 2021 14:07:02 by 18

I am having a flow where I convert some Word documents to PDF, when the Word document are being updated or created. Then it move the PDF to another location. This is all fine, but sometimes a PDF is already on the location when the flow creates a new one (step Create file 2), and then the flow fails 😐 Isn't it possible to make so that it will overwrite the existing file, if it is already there? 

pnr_0-1612188320814.png

 

  • Community Power Platform Member Profile Picture
    on 19 Dec 2023 at 16:11:03
    Re: Overwrite file if it already exist

    Hmm that will work but then can use the replace option. Also deletes the file.

     

    And also removes history.

     

    But anyway thanks for the suggestion

  • Nic-AF Profile Picture
    on 19 Dec 2023 at 15:40:51
    Re: Overwrite file if it already exist

    I don't have "Chunking" in my CreateFile action settings.

     

    I simply put a Delete action before the Create.  It doesn't seem necessary to check if the file already exist or not.  If file doesn't exist, the Delete doesn't complain.  To be safe, I configure the Create to run after Delete even though Delete fails.

  • vikas1606 Profile Picture
    206 on 19 Mar 2023 at 05:18:26
    Re: Overwrite file if it already exist

    It's an old thread but worth sharing if someone has the same issue. As @HEATFreight  mentioned above. I recently did this by turning off "Allow Chunking" in Create File setting. You can try to replace the existing file with a new file.

     

    vikas1606_1-1679202939990.png

     

     

  • HEATFreight Profile Picture
    1,020 on 25 Jan 2023 at 17:19:04
    Re: Overwrite file if it already exist

    No, the whole point is for everything to run as fast as possible so the user doesn't have to wait.

    The concurrency must be set to some number greater than 1, ideally something just larger than the maximum number of expected files to be uploaded, otherwise they would run sequentially and take N times as long, where N is the number of files.

    That's a terrible user experience. You can run "CreateFile" with as much concurrency as your heart desires (up to the max of 50) and it will add as many files simultaneously to the same record as you need it to.

    "AddAttachment" is limited in that it can only upload one file to a SharePoint list item at a time. Simultaneous file uploads to the same list item will error out with something like "the record is already being modified".

    "CreateFile" just works.

    Like I said previously, the run time of this flow has been reduced by roughly 50% or more simply by concurrently running "CreateFile" instead of (first deleting all existing conflicts before) synchronously running "AddAttachment".

    My flow is already just about as optimized as it can get.

  • Community Power Platform Member Profile Picture
    on 25 Jan 2023 at 16:26:57
    Re: Overwrite file if it already exist

    Great!

     

    Have you also checked setting concurrency control to 1 in the 'add attachment' step? And maybe building in delay after each attachment?

     

    Just a suggestion. But as usual involves trial and error. Even if you build it correct it might still not work.

  • HEATFreight Profile Picture
    1,020 on 25 Jan 2023 at 15:56:32
    Re: Overwrite file if it already exist

    Oh and another thing to add!

    The SharePoint "AddAttachment" action in Power Automate does not seem to be capable of concurrently editing the same record. So, in my use case, we can't use "AddAttachment" to simultaneously upload several files to the same list item. However, "CreateFile" has no such limitation, so you can concurrently upload as many files as you need to.

    I suspect that if you are working with document libraries instead of list items, then maybe you don't have to worry about the concurrency issue because you are already working with a folder path, like how "CreateFile" works. I suspect in that situation, other methods besides "CreateFile" may be able to concurrently upload multiple files, because your target is a folder. But when the target is a list item (still a folder but not treated as such when using "AddAttachment"), multiple simultaneous uploads are not allowed, except when you specify the list item using folder notation, as with the "CreateFile" action.

    tl;dr: Treat it like a folder ("CreateFile") and you can go asynchronous with your uploads. Treat a list item like a list item ("AddAttachment"), and you face the limitation of one file at a time.

  • Community Power Platform Member Profile Picture
    on 25 Jan 2023 at 15:54:02
    Re: Overwrite file if it already exist

    Yeah i know all these connectors are somehow related and can be converted to each other.

     

    But don't want to do too much tweaking of these connecters. It is supposed to be a low-code solution aiming to have a large user base. So not having to do difficult things and learn by trial and error but commonly used functions being standard available.

  • HEATFreight Profile Picture
    1,020 on 25 Jan 2023 at 15:48:28
    Re: Overwrite file if it already exist

    I should clarify that, in my use case, I need the "CreateFile" action to work regardless of whether or not the file exists yet. On the first run, the placeholder file we added before "CreateFile" preps the target location by creating the folder that my file needs to go to, but on subsequent runs, we skip the placeholder file because the folder already exists, and we skip deleting all existing conflicts because any file we send with "CreateFile" will overwrite conflicts.

    The result is that our flow to simultaneously upload several files to SharePoint runs twice as fast as before because we're not wasting time unnecessarily deleting older versions of the files or, on the first run, looking for older versions to delete which don't exist yet.

  • HEATFreight Profile Picture
    1,020 on 25 Jan 2023 at 15:42:38
    Re: Overwrite file if it already exist

    And by the way, my rule #1 above only applies if the folder does not exist yet. So in the case of a SharePoint list item, the attachments to that list item are saved in a folder, and that folder does not exist until you add attachments to the list item, so "AddAttachments" in Power Automate works even if no files have been added yet, because that action is apparently able to create the attachments folder, but "CreateFile" does not. I have not figured out how to create the folder first, so I add a placeholder file in my canvas app before the Power Automate flow runs, then when the flow runs "CreateFile" succeeds because the folder already exists because the canvas app has already added a placeholder file.

    I think in your case, all you need is for the destination folder to already exist, and then "CreateFile" should overwrite existing files successfully, assuming "chunking" is disabled in the settings for that "CreateFile".

  • HEATFreight Profile Picture
    1,020 on 25 Jan 2023 at 15:29:45
    Re: Overwrite file if it already exist

    It's the same thing.

    List items ARE folders.

    For some folder in a document library, everything I've said is still true. Just make sure the path is correct and follow my instructions, and "CreateFile" overwrites successfully.

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,660 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,004 Most Valuable Professional

Leaderboard