Power Apps Download Function | Download a File from Power Apps

Recently, I developed a leave management application. For this application, we are required to store the approved or rejected employee leave request files as PDFs in the SharePoint document library.

In this application, we are required to fetch the selected employees’ leave request PDF files from the document library and provide a way for them to download those files. We achieved this with the help of the Power Apps Download().

In this article, I will explain the Power Apps Download function and how to download a file from the Power Apps gallery with a few examples.

Power Apps Download Function

In Power Apps, the Download function allows users to download files directly from the app to their devices. It supports various file types and allows access to documents, images, and other content.

Syntax:

Download(Address)

Here,

  • Address = Required parameter; provide the address within the download function.

Power Apps Download File From Gallery

Let’s see how to download files from the Power Apps gallery. In the example below, I have two gallery controls: one contains employee leave requests, and the other contains pdf files of selected employees. When I click on the Download icon, the files are getting downloaded.

download file from power apps gallery

Here is the SharePoint list named “Employee Leave Request,” which has the following columns.

powerapps download file from sharepoint library

The SharePoint document library named “Leave Request Files” below contains the employees’ leave pdf files.

download sharepoint document libray files in power apps

Follow the steps below to achieve this!

Add the above SharePoint list and library to the Power Apps application.

1. In Power Apps, for the App object’s OnStart property, provide the code below to create a collection for storing SharePoint document library files.

ClearCollect(colEmployeeLeaveRequestFiles,'Leave Request Files');

Here,

  • colEmployeeLeaveRequestFiles = collection name.
  • ‘Leave Request Files’ = SharePoint document library name.
power apps download file from sharepoint library

2. In Power Apps, add a gallery control and connect it with the SharePoint list by providing the list name in its items property.

'Employee Leave Requests'
power apps download function

3. Add another gallery and provide the code below in its items property to fetch the PDF files of the selected user.

Filter(
    colEmployeeLeaveRequestFiles,
    StartsWith(
        Name,
        Gal_LeaveDetails.Selected.'Employee Name'.DisplayName
    )
)

Here,

  • The StartsWith() function will get the PDF files with the starting name matched with the gallery-selected employee name.
  • Filter() function only gets the gallery-selected employees to leave PDF files from the document library.
powerapps download file from sharepoint

3. Add a download icon to the PDF files presented gallery and provide the code below in its OnSelect property.

Download($"https://szg52.sharepoint.com/sites/RetailManagementSite/_layouts/download.aspx?SourceUrl=https://szg52.sharepoint.com/sites/RetailManagementSite/{ThisItem.'Full Path'}")

Here, change the URL “https://szg52.sharepoint.com/sites/RetailManagementSite/_layouts/” with your SharePoint site.

powerapps download file from gallery

4. The PDF image can be displayed statically or dynamically with the file extension. Since we have all PDF files, we can use the PDF icon next to each file.

To dynamically display an image of the file with its extension, add the code below to the Image property of the image control.

$"https://static2.sharepointonline.com/files/fabric/assets/item-types/24/{Last(Split(ThisItem.'File name with extension',".")).Value}.svg"

This URL fetches the image of the file with its extension.

powerapps download file without opening

5. Save and publish the app once. While previewing, click on the download icon next to the file to see that the file has been downloaded.

This way, we can download files directly from the Power Apps gallery view.

I hope you understand the Power Apps download function and how to download a file from the Power Apps gallery. You can follow this article while trying to download files from Power Apps.

Also, you may like:

>