How To Retrieve All Files from SharePoint Library Folder & Send an Email Attachment using Microsoft Flows
In this blog I will explain how to retrieve all files from a specified SharePoint folder and send email as an attachment.
Every flow needs a trigger to start with so here I am using a manual trigger.
Next step I am using flow step SharePoint List Folder which returns files contained in a SharePoint folder.
The return response is array of BlobMetadata which contains the below details.
Name | Path | Type | Description |
ItemId | ItemId | integer | The value that can be used to Get or Update file properties in libraries. |
Id | Id | string | The unique id of the file or folder. |
Name | Name | string | The name of the file or folder. |
DisplayName | DisplayName | string | The display name of the file or folder. |
Path | Path | string | The path of the file or folder. |
LastModified | LastModified | date-time | The date and time the file or folder was last modified. |
Size | Size | integer | The size of the file or folder. |
MediaType | MediaType | string | The media type of the file or folder. |
IsFolder | IsFolder | boolean | A boolean value (true, false) to indicate whether or not the blob is a folder. |
ETag | ETag | string | The etag of the file or folder. |
FileLocator | FileLocator | string | The filelocator of the file or folder. |
Next, we need to collect the file name and contents. For this we need to declare a variable type array called FilesArray.
Next step we need to construct a loop for reading all the SharePoint list folder contents. List folder contents will have files and folders. So within the loop I am checking whether the content is a folder or not. See below image.
Next, we need to construct rest of the logic under the yes condition for getting all the file names & contents to array variable which we declared earlier. To get the file content use flow step Get file content using path. Path property is available from the above step using Blobmetadata content. Append to array will have two properties ContentBytes and Name. See format below.
The expression for file ContentBytes is as follows:
body(‘Get_file_content_using_path’).$content
Note: There is a property called FileContent available from the Dynamic content, but this will result in error for flow step send email. So it’s important to use the above expression for the contentbytes.
Finally, outside the apply each loop use the send email flow action for sending all the files as one attachment.
Below is the final preview of the flow solution which we discussed above.
Thank you for reading.
Comments
Post a Comment