top of page
  • Ajith Madathil

How to retrieve files from a SharePoint library and send an email attachment (with Power Automate)

Updated: Apr 1, 2020


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:


body(‘Get_file_content_using_path’).$content

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.


3,682 views0 comments

Recent Posts

See All

The Compose action

Microsoft Power Automate (aka Microsoft Flow) provides lots of action steps out of the box. My favourite one is Compose. What does it do? What is the Compose action? The Compose action is like a stati

How to call an API using the Power Automate HTTP action

In this blog post I will access NASA's Astronomy Picture of the Day (APOD) API using Power Automate. The plan is to retrieve the picture of the day using the API and store it in a SharePoint document

Blog Categories
 

Beginner

Intermediate

 

Advanced

Power Automate Essentials

How can I help you?

I am happy to help at any time.  You can contact me via the official PowerAutomate community forum.  Tag me (@abm) on any post you make there if you would like to me take a look at it.

I am always available for both corporate training or 1-2-1 training for individuals. 

bottom of page