Creating Folders in OneDrive and SharePoint using Microsoft Flow

Microsoft Flow does not have an action to create folders in either OneDrive or SharePoint. To my mind this is an odd design choice by the Flow team. There are two ways to overcoming this shortcoming. The first is to use the Microsoft Graph or the SharePoint API in a HTTP action to create the folder. Whilst this offers maximum flexibility, as you could set other items like metadata and permissions, it strays into the grey area of Premium Flow licensing. It is also perhaps beyond the citizen developer. A far easier approach is using a Create File action and trick Flow into creating the folder. Perhaps trick is not the right word, especially as the Create File action hints at the possibility with the text ‘Add folders if needed‘ but it provides little guidance as to how. What happens is that a Create File action will create a new folder if it cannot find the folder you specify in the Folder Path field. That is the trick.

The clue…

In the example below, the re365 folder does not exist at the root level of my OneDrive. (Root level = top most level). The method works by creating a new file (in this case a text file) and then subsequently deleting the file to leave an empty folder (to be used in whichever way you need in your Flow).

Two steps to Folder creation in OneDrive

By adding the folder name re365 after the / (which represents the root level) in the Folder Path field causes OneDrive to create the folder first and then add a new text file called test.txt. Empty files can cause Flow to wobble and so I’ve included one word in the File Content field to ensure the file is not empty. The second action simply deletes the test file by calling it by its Id (which is an output of the previous step).

Proof!

The approach also works for SharePoint. In the example below I add the re365 folder to a Document Library called Shared Documents.

Two steps to Folder creation in SharePoint
Proof!

You can even dynamically name your folders by passing a string variable into the Folder Path item and nest your folder several levels down e.g. /re365/deep/deeperstill . The Action will create any missing hierarchy.

About the Author:

 am open minded about any technology that makes the lives of people easier and frees them to do what they do best! My focus is on building knowledge communities, efficient and effective information lifecycle management, and the sustained adoption of the Office 365 suite of products. I believe in configuration over development.

Twitter:  @buildbod

Reference:

Denton, S. (2020). Creating folders in OneDrive and SharePoint using Microsoft Flow. Available at: https://buildbod.com/2019/04/26/creating-folders-in-onedrive-and-sharepoint-using-microsoft-flow/

Share this on...

Rate this Post:

Share: