Flow files from OneDrive to SharePoint

Introduction

Recently, I had a business use case, where the user wanted to move the file as soon as the file was uploaded to OneDrive. You may ask, why not synchronize the SharePoint library instead of using One Drive for Business? The reason is that the library had a large volume of files, and the sync could take a lot of time based on bandwidth and resource availability on your machine. The other reason could be the user may want only the One Drive sync client folder and nothing else to save on the resources. This requirement can be easily converted to Business Automation using Microsoft's Power Automate Designer. Let us see how to achieve this in the steps below.

Pre-Requisites

  • You need to have standard SharePoint E3 or E5 licenses.
  • The good news is all connections are standard Power Automate actions. No premium actions are needed.

Step 1. Log in to the Power Automate designer portal using the URL https://make.powerautomate.com

Step 2. Click on ‘Create’ and choose to start from ‘Template’. Select the template that says, ‘Notify and Email when a new file is uploaded to OneDrive’.

Create

Notify

Step 3. On the next page, it would ask for permission to connect to ‘One Drive for Business’ and mobile notifications. Click on ‘Continue’.

One Drive for Business

Step 4. It should navigate to ‘New Designer’ by default. Below is the screenshot for reference.

New Designer

Step 5. In this case, I am deleting ‘Send me a mobile notification’. Since our focus is to move the files to the SharePoint site whenever a file is uploaded to ‘OneDrive’. You should see the 2 actions below.

Mobile notification

Step 6. Let us configure the first action ‘When a file is created (properties only). Here configure the folder in your OneDrive where the file will be uploaded.

First action

Here I have a folder in my ‘OneDrive’ called ‘SnowIncidents’. The use case is whenever a file is placed, I want to move to a SharePoint location.

Step 7. Let us use ‘Compose Action’ to get the File Path. And update the compose action to the following.

Compose Action

 File Path

By default, the file path property from the action ‘When a file is created’ gives some unique format with some GUID and folder path. Below is the example of full path for the file that is saved in the ‘SnowIncidents’ folder in OneDrive for Business.

/drives/b!0Ay6wkkPp0abzUR7WbtHa4xU8hLLqDNHvkqDONBmYZbMuXfPsyeiQ4ClAkusLNee/root:/SnowIncidents/JoinNewGMFCommunities.pdf

GUID

Step 8. We need only the path after the colon (:). Hence, we are using the ‘split’ function to split the string based on the colon. The output will be an array type and always start with the 0th index. Since we had only one colon, it gives us 2 elements in an array. Since we need the one after the colon, it would be at the first index.

Split

Step 9. While referring to path to one drive, the root library is always ‘/Documents’. Hence it is required to concatenate the file path with /Documents when trying to refer in ‘Move File’ action which is from SharePoint. Use ‘concatenate’ function just like below. Use the compose action and name as ‘Compose – Set File Path’.

Move File

Concatenate

Step 10. Add the action from ‘SharePoint’ called ‘Move file’. Configure the ‘Move file’ action.

  • Current Site Address: Input the value of the One Drive. Usually, the format is https://ordomain-my.sharepoint.com/personal/firstname_lastname_orgdomain_com
  • File To Move: the outputs of ‘Compose Action – Set File Path’.
  • Destination Site Address: The URL of the SharePoint site
  • Destination Folder: the folder where the file needs to be moved. Here I have set it to /Shared Documents/SnowIncidents
  • If Another File is Already There’: Leave it as ‘Replace’, which is the default option.

Step 11. Below is the complete ‘Flow Setup’.

Flow Setup

Step 12. You can also get the attached flow, for reference.

Validation

Step 1. Upload the file to your ‘OneDrive’ to the ‘SnowIncidents’ folder. Here, I have chosen the file as ‘TestMoveToSharePointSite_File.docx’.

SnowIncidents folder

Step 2. Observe after couple of minutes the file should automatically move to designated SharePoint online location. You should also be receiving notification that the file has bee n moved.

SharePoint online location

Test Move

Conclusion

Thus, in this article we have seen how to move the files from ‘One Drive for Business’ folder to SharePoint online using standard Power Automate actions.

References


Similar Articles