Retrieve Files from Dataverse with a Power Apps Download Button
Learn how to build a canvas button that downloads a document stored in a Dataverse file column by calling the Web API with Power Fx.
When you store files in a Dataverse file column, standard Power Apps controls like the PDF viewer or image control can display them, but they don't offer a straightforward way to download the binary file to the user's device. By composing a direct Web API URL and using the Download function, you can create a simple button that triggers a file download in the browser.
In this walk‑through you'll see a complete example: a project manager selects a contract in a gallery and clicks a button to download the associated PDF. All steps use a custom Dataverse table and environment variables for safe transportation between environments.
Scenario: Project Contracts Table
Imagine you're building a canvas app for a project management office. You have a Dataverse table named Project Contracts with these columns:
| Display Name | Data Type | Logical Name (example) |
|---|---|---|
| Contract ID | Text | nar_contractid |
| Contract Name | Text | nar_contractname |
| Contract File | File | nar_contractfile |
The table already contains a few records, each with a PDF attached in the file column.
Your canvas app shows a gallery of contracts, and each row has a Download button. When clicked, the button sends the PDF to the user's local machine.
1. Find Your Environment URL and Logical Names
The Web API endpoint follows this structure:
https://<environment_url>/api/data/v9.2/<table_logical_name>(<record_guid>)/<column_logical_name>/$value
You need three pieces of information.
Environment URL
Open the Power Platform admin center, select your environment, and copy the URL (e.g., org12345.crm.dynamics.com). Prepend https:// when building the final URL.
Table Logical Name
In a browser, navigate to https://<environment_url>/api/data/v9.2. The JSON result lists all entity sets. Look for the entry that matches your table – for example nar_projectcontracts.
You can also find the logical name by opening the table in make.powerapps.com, then inspecting the Advanced tab or the API settings.
Record GUID
Use the Web API to get a list of records from your table:
GET https://<environment_url>/api/data/v9.2/nar_projectcontracts
In the response, pick the nar_contractid value for the contract you want to download. Dataverse stores the primary key as a GUID.
Column Logical Name
Retrieve a single record to see its column names:
GET https://<environment_url>/api/data/v9.2/nar_projectcontracts(<guid>)
The file column appears as nar_contractfile. Add /$value at the end to request the binary content.
2. Build the Download Button
Inside Power Apps Studio, add a Button control to your screen. Set its OnSelect property to the following Power Fx code:
Download(
$"https://{LookUp('Environment Variable Values',
'Environment Variable Definition'.'Display Name' = "Environment URL",
Value
)}/api/data/v9.2/nar_projectcontracts({Gallery1.Selected.'Contract ID'})/nar_contractfile/$value"
)This code assumes you have a gallery named Gallery1 bound to the Project Contracts table, and that an environment variable named Environment URL holds your environment URL.
The GUID you pass in the URL must be the Dataverse primary key, not a custom identifier. Adjust Gallery1.Selected.'Contract ID' if your gallery shows a different field; make sure it maps to the ID column of the table.
3. Use an Environment Variable for Portability
Hard‑coding the environment URL ties your app to a single environment. Instead, create a Text environment variable inside a solution:
- In make.powerapps.com, open the solution that contains your app.
- Click New > Environment variable.
- Set Display name to
Environment URL. - Choose Data type = Text.
- In the Current Value field, paste your environment URL (e.g.,
https://org12345.crm.dynamics.com– include the protocol).
Back in the canvas app, add the Environment Variable Definitions and Environment Variable Values tables as data sources (they come from the environment’s default solution). Then use the LookUp pattern shown above to retrieve the value.
4. Test the Download
Publish the app. When you click the button, the browser should download the file. If nothing happens, check:
- The record GUID is correct and hasn’t been deleted.
- The column logical name matches the file column (not a text or image column).
- The environment variable is populated and the app can access its table.
- Your user account has Read permission on the table and the file column.
Performance and Security Considerations
- The
Downloadfunction is not delegable, but it only runs on the selected record, so performance is fine. - File size matters: Dataverse file columns can hold up to 128 MB. Very large files may take a moment to download; consider adding a loading indicator.
- The Web API endpoint respects your role‑based security. Users who cannot read the record or the file column will receive a 403 or 404 response.
Common Mistakes
| Mistake | Consequence |
|---|---|
Omitting /$value at the end of the URL | The API returns JSON metadata instead of the binary file. |
| Using display names instead of logical names | The Web API returns a 404 error. |
| Hard‑coding the GUID when you build a gallery | Every button downloads the same file. Use the gallery’s selected item ID. |
| Not adding the environment variable tables as data sources | The LookUp returns blank and the download fails. |
If you encounter an error, start by testing the URL directly in a browser. If it works there, the issue is likely in your Power Fx code or data sources.
Final Recommendation
The approach shown here is simple and effective for downloading files from Dataverse file columns. Always use environment variables for any environment‑specific values (URL, maybe table names) to make your app solution‑ready. For complex scenarios—like downloading multiple files at once or handling non‑PDF types—the same pattern works with any file column that returns binary data via $value.
References
- Original article by Matthew Devaney: Power Apps: Download File From Dataverse File Column
- Microsoft Learn: Retrieve a table row using the Web API
- Microsoft Learn: Perform operations using the Web API
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.