Skip to main content

How To Retrieve All Files from SharePoint Library Folder & Send an Email Attachment using Microsoft Flows


msflowsmallicon 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.

NamePathTypeDescription
ItemIdItemIdintegerThe value that can be used to Get or Update file properties in libraries.
IdIdstringThe unique id of the file or folder.
NameNamestringThe name of the file or folder.
DisplayNameDisplayNamestringThe display name of the file or folder.
PathPathstringThe path of the file or folder.
LastModifiedLastModifieddate-timeThe date and time the file or folder was last modified.
SizeSizeintegerThe size of the file or folder.
MediaTypeMediaTypestringThe media type of the file or folder.
IsFolderIsFolderbooleanA boolean value (true, false) to indicate whether or not the blob is a folder.
ETagETagstringThe etag of the file or folder.
FileLocatorFileLocatorstringThe 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.

Ref: https://mydevexperience.wordpress.com/2019/10/12/microsoft-flow-retrieve-all-files-from-sharepoint-library-folder-send-email-attachment/

Comments

Popular posts from this blog

Microsoft Dynamics 365 CRM Troubleshooting Solution Import Errors

Remember when CRM life was so much simpler that solutions did not yet exist? If you had separate development and production environments and you wanted to move your customizations, you simply clicked  Export Customizations  and voila! It was done. Those were the days. Nostalgia Warning – in case you’ve forgotten, here’s a screenshot to jog your memory: With CRM 2011, the concept of solutions was introduced, giving us a new set of powers – by picking individual entities, workflows, etc., we now had the ability to group together and move only those customizations we wanted to include in our solution. The next great solutions advancement came with CRM 2016: we can now select specific components within each individual entity – so instead of moving the entire contact entity, for example, we have the option of moving only a certain view or field within the entity. And we can do this without having to hack the xml in the zip file. (By the way, if you want to learn more abou...

How to Filter SubGrid Lookup view in Dynamics 365 CRM

How to Filter SubGrid Lookup view in Dynamics 365 CRM.  Please check the comments in the below code and do follow the steps accordingly and call the  filterSubGrid() funtion on onload. var LastQuery = ""; function filterSubGrid() { debugger; setSubgridLookupFiltering(); } function AddLookupFilter(entity_type, customFilter) { var subgridLookup = Xrm.Page.getControl("lookup_Contacts_Participants"); subgridLookup.addCustomFilter(customFilter, entity_type); } function setSubgridLookupFiltering() { var subgridAddButtonId = "Contacts_Participants_addImageButton"; //Try to get the element from both the current and the parent document. var subgridAddButton = document.getElementById(subgridAddButtonId) || window.parent.document.getElementById(subgridAddButtonId); //This script may run before the subgrid has been fully loaded on the form. If this is the case, //delay and retry until the subgrid has been loaded. if (subg...

How to prevent record from saving in Dynamics CRM using Javascript

  From time to time you might need to add some validation to the save event of an entity, this actually used to be an approach I would use on a regular basis but since the introduction of business rules have found myself doing this less and less. But still, knowing the ability is available is handy. When you define the onsave event function, you must tick the “Pass execution contact as first parameter” option. (See below) Having done that you can create an onSave function with code similar to the example I have shown below. Note forgetting the “(context)”, which will take the context parameter allowing you to prevent the save when needed. function onSave(context) { var saveEvent = context.getEventArgs(); if (Xrm.Page.getAttribute("telephone1").getValue() == null) { // *** Note: I am using an alert for testing a notification maybe better! alert("Put in a phone number!"); saveEvent.preventDefault(); } } Note: This simple example might be better achi...