cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
pnr
Frequent Visitor

Overwrite file if it already exist

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

 

25 REPLIES 25
stephankline
Community Support
Community Support

Hello,

 

Thank you very much for the screenshot and general idea of how you'd like the flow to operate.

 

In looking at what you have so far and your proposed result, it looks as though you may be missing a Condition control to check if the pdf already exists in the destination.  The basic logic looking something like this:

 

  • If file exists equals "Yes", then delete the found file with the recently converted pdf. 
  • If file does not exist, then create file (as you already have set up in an Action).

 

To see a similar working version of this for attachments, I was able to locate another thread that used a different trigger, but the end result matching up with what’d you like to do:

 

Save attachment to One Drive and OVERWRITE an exis... - Power Platform Community (microsoft.com)

 

Community Support Team - Stephan Kline

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

tom_riha
Most Valuable Professional
Most Valuable Professional

Hello @pnr ,

the 'Create file' action doesn't have a possibility to replace an existing file. I'd say you've got two options:

  1. If a file with the name already exists, delete the current file and create a new one as proposed by @stephankline .
  2. Create one more "shadow" document library on the site, create the file in the new library, and then use 'Move file' action to move the file to the main library. 'Move file' will allow you to replace the file if it already exists = Power Automate will take care of the deletion/creation of the new file in the main library.

image.png



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]
Anonymous
Not applicable

I am using the replace option and it somehow works. 

 

But what I don't like is that it moves the old file to the recycle bin instead of overwriting.

 

Some files get replaced a lot and then get many files in my recyble bin. 

 

Can it not just overwrite the existing file? And use version history if you want to see the file that has been replaced?

 

Thank you!

tom_riha
Most Valuable Professional
Most Valuable Professional

Hello @Anonymous ,

you can, but it's a bit more work: https://tomriha.com/how-to-update-not-replace-an-existing-file-in-power-automate/



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]
Anonymous
Not applicable

@tom_riha I know but was trying to avoid the extra work by using the standard function 😛

tom_riha
Most Valuable Professional
Most Valuable Professional

I can't even count how many hours I wasted by trying to avoid extra work... 😁



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]
Anonymous
Not applicable

I have a similar issue updating a PDF file attachment in list library. 

 

1. The update file doesn't update the file. Is this method only works for Document Library?

RajMalot_0-1662560562716.png

 

2. If you Delete the attachment, and Add Attachment. That results in file moved message.

Am I doing something wrong?

 

Anonymous
Not applicable

As far as I know updating file works.

 

Check if file exists --> If not create file. If it does exist use update. That way existing file is not sent to recycle bin.

Anonymous
Not applicable

Thank you, I do check if file exist.

RajMalot_0-1662562327020.png

 

Anonymous
Not applicable

I was unable to make the update file method to work with list attachment. Hence I tried other options suggested and it works fine now.

 

1. Get list item attachments

2. Delete the list attachment if exists

3. Add attachment to list item

 

RajMalot_0-1662654055222.png

 

Anonymous
Not applicable

Think you need to add the 'get attachment content'  step and add the attachment content from there

The solution to this problem is to use "Create File" instead of "Add Attachment".

This blog says you need to disable "Allow chunking" and you will be able to overwrite existing SharePoint files, but in my testing that is not necessary. You do not need to disable chunking.

 

All you need to do is use "Create file" and the file will be created or overwritten seamlessly without having to check if it exists and delete it first! "Add Attachment" gives an error if the file already exists, but "Create File" works whether it exists or not. "Add Attachment" is specific to attaching files to list items, but "Create File" works for any folder in SharePoint. "Lists" is a folder and each list is itself a folder and the attachments to a list is a folder and each list item is a folder.

Therefore, if you want the file to attach to a list item in a SharePoint list, the syntax for "Folder Path" in your "Create File" action is as follows:

/Lists/<List Name>/Attachments/<List Item Id>

 

Anonymous
Not applicable

Thanks.

 

From my experience the create file used to fail if the file already existed.

 

But will check it out anyway.

 

I found out that if you use "CreateFile" to add an attachment to a SharePoint list item, you must already have some attachment there or it will fail because the "attachments" folder does not exist yet. My workaround was just to add a small placeholder image in Power Apps to every record that requires attachments.

Then I run "CreateFile" using the below code to designate the target list item as a folder:

/Lists/<List Name>/Attachments/<List Item Id>

 
You must have chunking disabled! On the "CreateFile" action, click settings and disable chunking.

If you don't disable chunking, then it's possible the "CreateFile" will fail to overwrite the existing file.

As long as two criteria are met, "CreateFile" for an existing file overwrites the existing file no problem:
1) - the SP list item must already have some file attached to it

2) - chunking must be disabled or you will see failures with large files. larger files will run as chunked, and that will fail to overwrite.

Anonymous
Not applicable

Hmm my question was related to creating a file in a folder, not to adding an attachment to a list item (I would use update item for that).

 

But maybe these are same actions I don't know.

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.

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".

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.

Anonymous
Not applicable

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.

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (1,156)