Microsoft Flow: create a file based on another file in SharePoint

Why?

One of the very first human actions you would want to automate is the creation of files; wheither it are new documents based on a template or copying documents from location A to location B.

What?

This post will be a basic explanation of the very first way, it was possible to create documents based on other documents. We have a document in a Template library in SharePoint and we want that document to act as a source file for a completely new destination file in new library in SharePoint.

How?

I often use a variable like varWebUrl so I can enter the URL of the (SharePoint) site once and use it in multiple actions. It also makes the flow more reusable in other sites without having to update all related actions. If you need the metadata from a specific list or library in your action, you would need to use the actual URL the first time before using the variable to prevent runtime errors.

1) First there is the source file in a library and starting in the Flow we will use a Get file or Get files action to get the Identifier that source file. From this file we will retreive all the metadata using the Get file metadata action:

2) Then we get the content of the file using the Get file content action:

3) Finally we can create the file using the Create file action:

The code in the File Name property:

@{variables('varItemName')}_@{body('Get_file_metadata_FoundTemplate')?['Name']}

I combine a variable varItemName that is guaranteed unique with the Name including the file extension we retrieved from the Get file metadata action. Including the file extension can be very important.

So since the beginning of Flow there have been a few ways that can achieve this result shorter, but from my experience this is one of the most reliable way that can be used in a lot of differenct scenarios.

2 thoughts on “Microsoft Flow: create a file based on another file in SharePoint

Leave a comment