Copying or moving files from one document library to another is one of the common scenarios in SharePoint when it comes to document management. It could be as simple as moving selected documents to, say, an archive document library.
Using flow you can easily orchestrate this and include any custom business processes you have as well.
Depending on where you are copying or moving the file, you may need to select different set of actions to accomplish the task. Lets look at them below.
Same SharePoint site
In this scenario, you have the source and destination libraries in the same SharePoint site . In this case, you can use the Copy to and Delete file actions available under SharePoint.
I use a manual trigger for a selected item, meaning, the option to run this flow is available to individual documents in the configured library, as shown below. You can very well use other automated triggers such as, when a file is created or modified.
Here is the complete flow:
Copy to action:
Given a source file path and destination file path for a particular SharePoint site, this action will copy the file from the source to the destination path.
The paths are relative, so if it is the ‘Shared Documents’ root folder you want, then:
Shared Documents/<file name>
As you can see in the action, we get the path of the file from Get item action. If you do want to get the file metadata, you can use the Get file metadata action as well. The destination path, in my case, I am using a library Archive and its root folder.
If you want to use a different folder, you can use:
Archive/<folder name>/<file name>
Note that the folder will be created if it doesn’t exist.
Delete file action:
Once the file is copied, we then use the Delete file action to delete the file from the source destination. To do this, we use the file identifier available from the Get item which is the source file.
Different SharePoint site
If you are copying or moving the file to a different site, then you will need to use the Create file action instead of the Copy to action. Of course, in order to create the file, you will need the file content. To get the file content, you can use the Get file content action.
In the create file action, you can either pick the path using the picker or specify the relative for the folder path.
Rest is pretty simple – give a name and then the file content from the Get file content action.
One thing to note is that you might have trouble copying/moving files > 100 MB. This is a known limitation right now with these actions.