SharePoint Document Downloads in Power Apps: The Force Download Trick
Save files from a SharePoint document library straight to the user’s device without opening in the browser using a simple URL tweak in Power Apps.
When you need to give app users a one‑click way to pull a file from a SharePoint document library onto their computer, the built-in Download function often opens the file in a browser tab instead of saving it directly to the Downloads folder. This article shows a small but effective workaround: using SharePoint’s own download.aspx endpoint to force the browser to download the file. You’ll build a gallery that lists documents and lets users download any file with a single press.
Scenario – Legal Document Retrieval
A law firm wants its paralegals to quickly access signed contracts stored in SharePoint. The app should show a list of documents, display the correct file type icon, and allow a direct download to the paralegal’s device. We’ll walk through creating this app from scratch, using a SharePoint document library named Legal Documents.
Prerequisites
- A SharePoint document library with at least a few documents uploaded (any type – PDF, DOCX, XLSX, etc.).
- A Power Apps environment with a blank canvas app.
- User accounts that have at least Read access to the library.
Step 1 – Connect the SharePoint Library to the App
In Power Apps Studio, create a new blank app. Add a Vertical gallery (or any list control) to the screen. Open the Items property of the gallery and connect to your SharePoint library.
'Legal Documents'
After the connection is made, the gallery automatically includes the columns you need: 'File name with extension' and 'Full Path'.
Step 2 – Show the File Name and a File Type Icon
You want to display the file name next to an icon that indicates the file type (PDF, Word, Excel, etc.). Set the gallery layout to Image and Title if you prefer, or adjust manually.
Label for file name
Select the label inside the gallery and set its Text property:
ThisItem.'File name with extension'
Image for file icon
SharePoint provides a CDN that serves SVG icons for every known file extension. Use the Image property of an image control (or the gallery’s image element) with this formula:
"https://static2.sharepointonline.com/files/fabric/assets/item-types/24/" & Last(Split(ThisItem.'File name with extension', ".")).Value & ".svg"
This extracts the extension from the file name and builds the URL to match the appropriate icon.
Step 3 – Add a Download Button
Replace the default gallery icon (often a right arrow) with a Download icon. Select the icon and change its Icon property:
Icon.Download
Give it a distinct color so it stands out:
- Color:
Color.Black - Fill:
Color.LightBlue
Step 4 – The Force Download Trick
The standard Download function calls the raw file URL, which often prompts the browser to display the file inline (especially for PDFs). To force a save‑to‑disk action, use SharePoint’s download.aspx page. This endpoint sends the correct Content-Disposition: attachment header that tells the browser to download rather than open.
In the OnSelect property of your download icon, place this call:
Download("https://yourtenant.sharepoint.com/sites/LegalDocuments/_layouts/download.aspx" & "?SourceUrl=https://yourtenant.sharepoint.com/sites/LegalDocuments/" & ThisItem.'Full Path')Important: Replace
https://yourtenant.sharepoint.com/sites/LegalDocumentswith the actual root URL of your SharePoint site. You can find this by opening the library in a browser and copying the URL up to the document library name (but including the site part).
The 'Full Path' field contains the full server‑relative path of the file (including the library name, subfolders, and file name). By appending it to the SourceUrl parameter, the download.aspx page knows exactly which file to serve.
Step 5 – Test the Experience
Preview the app and press the download icon. In modern browsers (Edge, Chrome, Firefox) the file should appear in the download notification area and then be saved to your default Downloads folder. Files that were previously opened in a new tab (like PDFs) will now be downloaded directly.
Security and Performance Considerations
- The
Downloadfunction still respects SharePoint permissions. Users must have at least Read access to the document library; otherwise the download.aspx call will fail. - No delegation issues exist with this pattern because you are only reading the file metadata from the gallery and then calling
Downloadwith the constructed URL. - For large files, the download time depends on the file size and the user’s network. SharePoint streaming limits still apply.
Common Mistakes and Troubleshooting
| Issue | Likely Cause | Fix |
|---|---|---|
| File opens in browser instead of downloading | Using the direct file URL instead of download.aspx | Make sure the URL begins with .../_layouts/download.aspx?SourceUrl=... |
| “Access denied” error | User lacks permissions on the SharePoint library | Verify the user’s role; grant at least Read access |
| Icon shows as broken image | The extension is not recognised by the SharePoint CDN | The icon CDN covers most common types. For unusual extensions, provide a fallback static image |
| Gallery shows no files | Library name is misspelled or connection not established | Re‑create the data source using the exact library name |
Recommendations
- Always use the
download.aspxURL when you want a true save‑to‑disk experience. Do not rely solely on theDownloadfunction with a plain file URL. - Consider storing the SharePoint site root URL in a global variable or a custom environment variable so you can reuse it across multiple screens.
- If your library uses versioning, the
'Full Path'field points to the current (major) version. To download a specific version, append&VersionId=<ID>to theSourceUrl.
References
- Original article that inspired this approach: Power Apps: Download File From SharePoint Document Library by Matthew Devaney
- Microsoft Learn: Download function in Power Fx
- Microsoft Learn: App and data sources overview for Power Apps
Learn how small coding practices—like using descriptive names, flattening conditions, and simplifying logic—can make your apps easier to update and less error-prone.
Move past the gallery and discover the hidden patterns for validation, navigation, and smart submission handling in your data entry forms.
PowerShell unlocks admin capabilities that the Power Platform admin center simply doesn’t offer—from recovering deleted apps to blocking trial licenses. Here’s how to wield them safely.