How to retrieve files from a SharePoint library and send an email attachment (with Power Automate)
Updated: Apr 1
Every flow needs a trigger to start with so here I am using a manual trigger.
Next, I am using the action List Folder which returns files contained in a SharePoint folder.
The return response is an array of BlobMetadata which contains the below properties.
NamePathTypeDescriptionItemId (integer) - The value that can be used to Get or Update file properties in libraries.
Id (string) - The unique id of the file or folder.
Name (string) - The name of the file or folder.
DisplayName (string) - The display name of the file or folder.
Path (string) - The path of the file or folder.
LastModified (datetime) - The date and time the file or folder was last modified.
Size (integer) - The size of the file or folder.
MediaType (string) - The media type of the file or folder.
IsFolder (boolean) - A boolean value (true, false) to indicate whether or not the blob is a folder.
ETag (string) - The etag of the file or folder.
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.
Now we need to construct a loop for reading all of the SharePoint library contents. This could be files or folders, so within the loop I am checking whether the content is a folder or not. See image:
Now we need to construct the rest of the logic under the Yes condition, and set all of the file's properties to the array variable which we declared earlier.
To get the file's content, we use the action Get file content using path. The Path property is available from the above step using the Blobmetadata content.
The Append to array variable action will have two properties - ContentBytes and Name. See the setup below.
The expression for the property ContentBytes is as follows:
Note: There is a property called FileContent available from the Dynamic content, but this will result in an error when sending the email. So it is important to use the above expression for Contentbytes.
Finally, outside the Apply to 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.