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:
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.
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'
Step:3
Initialize the Variable Enter the variable name and choose the variable type as Array to store all the file links.
Step:4
Select apply to each action and dynamic content values, so that it loops through all the filtered files.
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')
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:
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]
Step:6
Save and run the flow by selecting the run flow option. Once the flow runs successfully, like below:
We can see the email will the Sharable links. When we select the link, it redirects to the Particular file in the document library.
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'
Step-3:
Initialize the Variable Enter the variable name and choose the variable type as Array to store all the Folder links.
Step-4:
Select apply to each action and dynamic content values, so that it loops through all the filtered folders.
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')
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:
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 Folder passing the below expression.
variables('FolderLinks')?[0]
For HRDetails Folder, pass the below expression
variables('FolderLinks')?[0]
Step-6:
Save and run the flow by selecting the run flow option. Once the flow runs successfully, like below:
We can see the email will the Sharable links. When we select the link, it redirects to the Particular folder in the document library.
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:
- Convert HTML to PDF in Power Automate
- Create an Excel file from SharePoint list items using Power Automate
- Create SharePoint lists from JSON using Power Automate
- Create a Folder in SharePoint using Power Automate
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.