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 / SharePoint document - ...
Power Automate
Unanswered

SharePoint document - copy file - existing to new version

(1) ShareShare
ReportReport
Posted on by

Hello


When copying a document (docx) from one library to another in SharePoint online with Flow:

If a file with a similar name exists, is it possible to add the copy as a new version of the file in the destination library?


I tried using the action 'Copy File' but the possible options 'copy with new name' or 'replace' do not deliver what I want.
I tried retrieving the SharePoint file content and sending an http request to Sharepoint:

_api/Web/getfolderbyserverrelativeurl('LIBRARY1')/files/add(overwrite=true,url='PATHTOFILE')
body of request = File Content

This does create a new version, but the word document becomes corrupt/unreadable.


Thanks

Categories:
I have the same question (0)
  • v-zhos-msft Profile Picture
    on at

    Hi @Anonymous ,

    I have made a test for your idea.

    I afraid that there is no way to achieve your needs in Microsoft Flow currently.

    You can't store two files with the same name in one floder.

    You can choose 'copy with new name' or 'replace' the file content.

     

    Best Regards,

    Community Support Team _ Zhongys

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

     

  • danmitchell36 Profile Picture
    268 on at

    The only solution I could think to accomplish this would be to use a conditional that loops through every document in the library and checks to see if any documents have the same name as the new document. If there is a document with the same name you could update the file content with the file content of the new document.

  • Verified answer
    Community Power Platform Member Profile Picture
    on at

    Thank you both for taking the time to find a solution.

    Eventually i came up with a solution myself and it's as simple as:

    Get File Content > Create File

    No need for http calls to SharePoint. Using the action 'Create File' has the underlying function to check if there is already a file with a similar name. If so, it automatically adds the content to the existing file as a new major version.

  • MortenT Profile Picture
    29 on at

    Watch out, though.. 

     

    "Get File Content" can only have a buffer of 100MB pr. file

    /Morten

  • mboonie Profile Picture
    164 on at

    I wonder if that action has been changed? When I try using Create File with a library that has Versioning enabled (major versions, keep last 500), I get this error:

     

    A file with the name Shared Documents/Forecast and Reporting.xlsx already exists. It was last modified by...

     

    I really need to create a new version of the worksheet (not a new instance) because parts of it are being displayed on a modern page. The File Viewer web part throws an error if the file being displayed is completely replace; it only updates if it's a new version of the file. Otherwise the web part has to be edited and the file reloaded.

     

    Has someone actually used Create File to make a new version lately?

     

  • NPrice99 Profile Picture
    1,302 on at

    Hi @mboonie 

     

    I have hit the same problem.

     

    Repeated calls to Create File now fail with "A file with the name  ......already exists".

     

    I have checked the document library and versioning is switched on and I can have 100 versions.

     

    Has there been an update to the SharePoint connector so this has now stopped working ?

     

    Regards

     

    Nigel

  • mboonie Profile Picture
    164 on at

    Yeah, I ended up having to use a Condition: I try to Get Items with the same name, and if the length() of the value returned is 0 (i.e. there are no files with that name), I use Create Item; otherwise, I use Update Item to make a new version.

    I'm sure they must have modified that connector (and, in true Microsoft fashion, left us to discover it on our own, as it's still documented that way on their site.)

    Connectors are modified all the time without telling us, it seems. I suppose (and hope!) most changes are harmless, but who knows? For example, I noticed this week that the ID of a list item used as a Workflow trigger has gone from triggerBody()?['ID'] to triggerOutputs()?['body/ID'].

    I hope it's for a good reason.

  • ekud Profile Picture
    3 on at

    Update item works. 

    thanks for the tip ! 

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

#2
Tomac Profile Picture

Tomac 406 Moderator

#3
abm abm Profile Picture

abm abm 245 Most Valuable Professional

Last 30 days Overall leaderboard