Create SharePoint Folders Dynamically in MS Flow

To manage files smoothly, it will be easier if the files will be stored inside a folder. You can add a file inside a one level folder or in a nested one.

In our previous blog where we copy files to another list, we noted there that the folder should exist first before you copy the files. If the copying of files is automated, the creation of folders should also be dynamic, so it won’t cause any problems.

Here’s how you create folders dynamically.

In this document library, we have the Reports folder.

 

Inside the Reports folder, we have the January and February folders.

The photo below will show our destination folder.

Creating Folders

Currently, there are no actions in MS Flows that are specifically designed for creating folders; however, we can use the Send an HTTP Request to SharePoint action.

Since there is no trigger that this is for an event when a folder is created in a list, we can use the When a file is Created action. This will run every time a folder or a file is created.

To input Site Address and Library Name, follow the guide below:

Site Address: Add the site address of the source folder
Library Name: Name of the source library
Folder: Select the file path by clicking the folder icon
Select the Name of the source document library.

After setting it up, you can now create the folder.

Now, let’s set up the Send an HTTP Request to SharePoint action. Follow the guide below.

Site Address: Add the site address of the destination folder
Method: We will be using POST because we are about to create an item in a list.
Uri: _api/Web/folders/add(‘’)

We will be using name and the folder path that were retrieved from the trigger action.

You may add these two items in the Headers field of the action:

Accept: application/json;data=verbose
Content-Type: application/json;data=verbose

Body: We will leave this field blank.

Note that you can also add a Condition action before creating the folder to check whether the file created is a folder. There is the isFolder metadata that is retrieved by the When a File is Created action.

You can use this in your condition for a validation of the created file to prevent errors.

Sample Output

When the folders in the Source Site are created, it will automatically create the same folder in the Destination Document Library.

Add a Comment

Your email address will not be published. Required fields are marked *