“Part of my requests are also attachments, but the Power Apps just opens one file, downloads the other – can I somehow download all the files?”
Recently I was building a few Power Apps applications for approval processes, where part of the requests were files. Let it be SharePoint list item attachments or files in a separate SP document library, in both cases I needed to show them. Yet it turned out to be quite a challenge to provide the files in a user friendly way. When I used the attachments control some files were corrupted after download. The other option was some Power Automate flow, making the solution more complicated than necessary…
There had to be a better way to allow users to download all the files!
Download the files directly
The files in SharePoint can be located in two places – in the list item attachments, or in a document library. We’ll look on both cases.
Files as item attachments
Even if it’s item attachments, I prefer to show them in a gallery. Add the gallery and as use the item attachments as Items.
Add another Label for the download link…
…using the Download(…) function as OnSelect that’ll call the SharePoint file download url. It looks as below. If you’re not sure how to build a string with $ check this article by Matthew Devaney.
Download(
$"https://<org>.sharepoint.com/sites/<SPsite>/_layouts/download.aspx?SourceUrl=<filePath>"
)
Note: <…> are placeholders, replace them including the < and >!
If you’re using list item attachments, the <filePath> is accessible under ThisItem.AbsoluteUri.
Download(
$"https://<org>.sharepoint.com/sites/<SPsite>/_layouts/download.aspx?SourceUrl={ThisItem.AbsoluteUri}"
)
Once you click on such label it’ll download the file.
File from a document library
The same approach can be used also on files stored in a document library. Again, start with a gallery showing the files and add a label. The only difference will be in the last part of the download url – files in document library give you ‘Full Path’ instead of ‘AbsoluteUri’.
Download(
$"https://<org>.sharepoint.com/sites/<SPsite>/_layouts/download.aspx?SourceUrl={ThisItem.'Full Path'}"
)
Summary
I found the Download(…) function to be the most reliable way to download file from SharePoint in Power Apps. Show the files in a gallery, let it be item attachments or files from document library, build the download link using the SP site and file path, and download it. All files will be behave in the same way – you click i a link and the file will start downloading, let it be word, pdf, zip, or any other file type.
I am unable to download the same file on clicking of button while using Power Apps desktop. It will be great if you can provide an alternative for this;
Using the following: Download(
$”https://.sharepoint.com/sites//_layouts/download.aspx?SourceUrl={ThisItem.’Full Path’}”
)
Thank you SO much for this post! I have been asking Copilot every way I could think of for this functionality and this worked perfectly! Much appreciated!!