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.
Here is the SharePoint list named “Employee Leave Request,” which has the following columns.
The SharePoint document library named “Leave Request Files” below contains the employees’ leave pdf files.
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.
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'
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.
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.
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.
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:
- Power Apps search function
- Power Apps add columns function
- Power Apps count rows function
- Power Apps date filter function
- Create Status Indicator Using Power Apps
- Power Apps Copy Function
- Patch Gallery Items in Power Apps
- Disable Power Apps Permissions PopUp Consent Form
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com