How to create a sharing link for a file or folder using Power Automate?

This Power Automate tutorial will show us how to create a sharing link for a file or folder using Power Automate.

Scenario:
The flow uses a manual trigger, and we will filter the File and Folder separately in the Get File Properties action based on content type. We will loop through all the filtered values and create a Sharing link by using Create Sharing link file or folder action and store them in an array using flow.

Finally, we will email the users the Shareable link to access the file or folder by using Send an email action.

Create a sharing link for a file or folder using Power Automate

Here we will see two examples; the first teaches how to create a sharing link for a file, and the second helps create a sharing link for a folder.

Create a sharing link for a file using Power Automate

Let us see how to create a sharing link for a file or folder using Power Automate flow.

Example:1

Follow the below steps to create a sharing link for a file using Power Automate.

Step:1

  • Open the SharePoint Online Document Library; here, you can see two folders and two Excel workbooks called EmployeeDetails and HRDetails.
  • Now to view the Content-Type column, Expand All Documents-> choose Edit Current View as below:
How to create a sharing link for a folder using Power Automate flow

Select Content type and Click on the Ok button; refresh the document library page, Content type column will be added. And the content type column will be added to our SharePoint document library view.

create a sharing link for a file using Power Automate flow

Step:2

Select + New step and choose the Get Files (Properties only) action from the action trigger. Then Provide the details below:

  • Site Address – Choose SharePoint site address
  • Library Name – Choose the document library
  • Filter Query – apply the below filter query code
ContentType eq 'Document'
Example to create a sharing link for a file using Power Automate

Step:3

See also  Power Apps Data Table [Complete Guide]

Initialize the Variable Enter the variable name and choose the variable type as Array to store all the file links.

Example to create a sharing link for a file using the Power Automate

Step:4

Select apply to each action and dynamic content values, so that it loops through all the filtered files.

Example to create a sharing link for a file using the Power Automate flow

Add +new step and select the Create sharing link for a file or folder action from action triggers. Then configure the below details:

  • Site Address – select the SharePoint site
  • Library Name – Choose the SharePoint Document Library where the file exists
  • Item Id – Pass the dynamic content File ID
  • Link Type – Either we can choose view only or we can select view and edit option.
  • Link Scope – Either we can select People in Organization only or we can choose Anyone with this link, including Anonymous users.
  • Link Expiration – We can set the link expiration here; I have set it for 3 days, for that, pass the below expression.
addDays(utcNow(), 3, 'yyyy-MM-dd')
How to create a sharing link for a file or folder using Power Automate

Add +new step and select Append to Array variable action and select the name and in the values section, pass the dynamic content of Sharing Link as displayed below:

Example to create a sharing link for a file using Microsoft flow

Step:5

Select +new step and send email action, Then Provide the parameters such as:

  • To- Set the user from the dynamic content
  • Subject- Give a subject to the email.
  • Body- Specify the body using the dynamic content we will add a link to the email using <a href> tag.

We will get Sharing link from the stored array variable for the Employee File pass the below expression.

variables('FileLinks')?[0]

For HRDetails File, pass the below expression

variables('FileLinks')?[1]
create a sharing link for a file using the Power Automate flow

Step:6

See also  How to Send Birthday Email using Power Automate?

Save and run the flow by selecting the run flow option. Once the flow runs successfully, like below:

power automate create sharing link for a file or folder

We can see the email will the Sharable links. When we select the link, it redirects to the Particular file in the document library.

create sharing link for a file using the Power Automate flow

This is how to create a sharing link for a file using Power Automate.

Create a sharing link for a folder using Power Automate

Example:2

Follow the below steps to create a sharing link for a Folder using Power Automate.

Step-1:

From the above example, follow step 1, where two folders are presented inside the document library. Enable the Content type in the view as explained.

Step-2:

Select + New step and choose the Get Files (Properties only) action from the action trigger. Then Provide the details below:

  • Site Address – Choose SharePoint site address
  • Library Name – Choose the document library
  • Filter Query – apply the below filter query code
ContentType eq 'Folder'
How to create a sharing link for a file using Power Automate flow

Step-3:

Initialize the Variable Enter the variable name and choose the variable type as Array to store all the Folder links.

Example to create a sharing link for a file using Power Automate flow

Step-4:

Select apply to each action and dynamic content values, so that it loops through all the filtered folders.

Example to create a sharing link for a file using the Power Automate flow

Add +new step and select the Create sharing link for a file or folder action from action triggers. Then configure the below details:

  • Site Address – select the SharePoint site
  • Library Name – Choose the SharePoint Document Library where the file exists
  • Item Id – Pass the dynamic content File ID
  • Link Type – Either we can choose view only or we can select view and edit option.
  • Link Scope – Either we can select People in Organization only or we can choose Anyone with this link, including Anonymous users.
  • Link Expiration – We can set the link expiration, here I have set it for 3 days, for that pass the below expression.
addDays(utcNow(), 3, 'yyyy-MM-dd')
How to create a sharing link for a file or folder using Power Automate

Add +new step and select Append to Array variable action and select the name and in the values section, pass the dynamic content of SharingLink as displayed below:

Example to create a sharing link for a file or folder using Power Automate

Step-5:

See also  Power Automate error: Cannot find the resource for the request addroleassignhments

Select +new step and send email action, Then Provide the parameters such as:

  • To- Set the user from the dynamic content
  • Subject- Give a subject to the email.
  • Body- Specify the body using the dynamic content we will add a link to the email using <a href> tag.

We will get Sharing link from the stored array variable for the Employee Folder passing the below expression.

variables('FolderLinks')?[0]

For HRDetails Folder, pass the below expression

variables('FolderLinks')?[0]
create a sharing link for a folder using the Power Automate flow

Step-6:

Save and run the flow by selecting the run flow option. Once the flow runs successfully, like below:

power automate create sharing link for a file or folder

We can see the email will the Sharable links. When we select the link, it redirects to the Particular folder in the document library.

create a sharing link for a folder using Power Automate flow

This is how to create a sharing link for a folder using Power Automate.

In this Power Automate tutorial, we saw how to create a sharing link for a file or folder using Power Automate.

You may also like:

>