Power Apps: Download File From SharePoint Document Library
Power Apps: Download File From SharePoint Document Library Posted by - Matthew Devaney on - March 31, 2024 19 Comments With Power Apps you can download a fil...
- Published
- Reading time
- 4 min read
Before you start
Is this guide for you?
- Best entry point
- SharePoint
- Time investment
- 4 min read
Imported reference from Matthew Devaney's blog for learning purposes. Original: https://www.matthewdevaney.com/power-apps-download-file-from-sharepoint-document-library/. Author: Matthew Devaney.
Power Apps: Download File From SharePoint Document Library Posted by - Matthew Devaney on - March 31, 2024 19 Comments
With Power Apps you can download a file from a SharePoint document library to the user’s computer. Depending on the browser’s settings the file might save to the downloads folder only or it might open immediately in a new browser tab upon download. My preferred method uses a special trick to force Power Apps to save to downloads folder only. In this article I will show you how Power Apps can download a file from a SharePoint document library. Table of Contents Introduction: The Vendor Invoices App Setup The SharePoint Document Library Create A List Of Vendor Invoices
Show The Filename And File Extension Icon Create A File Download Button
Download A Selected File From SharePoint
Test The File Download Button In Power Apps Introduction: The Vendor Invoices App
Project managers at a construction company use the Vendor Invoices App to view a list of invoices and download the selected invoice. The invoices are stored in a SharePoint document library. Setup The SharePoint Document Library
Create a new SharePoint document library named Vendor Invoices and add upload several documents to it. The documents may be of any file type (pdf, docx, xlsx, etc.). Create A List Of Vendor Invoices
Open Power Apps Studio and create a new app from blank. Add a vertical gallery to the app.
Then connect the Vendor Invoices SharePoint document library to the app.
Use this code in the Items property of the gallery to display the Vendor Invoices files. 'Vendor Invoices' Code language: JavaScript ( javascript )
Select the layout Image and Title to show a single image control and text control on each line.
Show The Filename And File Extension Icon
For each file in the gallery we want to display the filename and and icon.
Use this code in the Text property the label to show the filename and extension. ThisItem. 'File name with extension' Code language: JavaScript ( javascript )
The image beside the filename will show a file extension icon.
Use this code in the Image property of the image. It is not necessary to load every file extension icon into the app. Instead, we can use the same static image assets as SharePoint. The code below extracts the file extension and then targets the proper SharePoint URL.
$ "https://static2.sharepointonline.com/files/fabric/assets/item-types/24/{Last(Split(ThisItem.'File name with extension'," . ")).Value}.svg" Code language: JavaScript ( javascript ) Create A File Download Button
We want the user to press a button next to the filename to download the file to their device. Select the existing Next Arrow icon in the gallery and change it to a download icon.
Use this code in the Icon property of the Icon. Icon .Download Code language: CSS ( css )
Then use this code in the icon’s Color and Fill properties to style it. Color : Color .DarkBlue Fill : Color .AliceBlue Code language: CSS ( css )
Download A Selected File From SharePoint
The final step is to download the file to the user’s device when they press the download button. We only want it to download directly to the user’s device. And we want to prevent it from opening immediately.
Use this code in the OnSelect property of the download icon to download the file. Replace the SharePoint site path with your own SharePoint site.
Download($ "https://matthewdevaney.sharepoint.com/sites/MatthewDevaneyBlog/_layouts/download.aspx?SourceUrl=https://matthewdevaney.sharepoint.com/sites/MatthewDevaneyBlog/{ThisItem.'Full Path'}" ) Code language: JavaScript ( javascript )
As an example, we can get the SharePoint site path from a web browser while viewing the Vendor Invoices document library.
Test The File Download Button In Power Apps
We’re done. Press the download button to test downloading the file to your device. Did You Enjoy This Article? 😺
Subscribe to get new Copilot Studio articles sent to your inbox each week for FREE Enter your email address Sign Me Up Questions?
If you have any questions or feedback about Power Apps: Download File From SharePoint Document Library please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion. Matthew Devaney M365 Copilot Power Apps
How To Create Copilot Custom UI Widgets In Power Apps
Tagged
SharePoint
Have a Microsoft 365 topic idea?
Share article suggestions, community session ideas, corrections, or real-world scenarios for future nxtM365 learning notes.
Keep learning Microsoft 365
Explore more practical guides for SharePoint, Power Platform, Copilot Studio, migration, automation, governance, and security.
Continue learning
Related tutorials
Related questions
Related comparisons
Next action