When building apps with PowerApps and Dataverse, displaying and downloading documents stored in file columns can be tricky — especially when those files are stored in Azure Blob Storage behind the scenes. In this tutorial, I’ll walk you through how to:
✔️ Display files in a PowerApps gallery
✔️ Show the file name from a Dataverse file column
✔️ Add a Download button that uses the Dataverse Web API
✔️ Make your app portable using environment variables
Let’s dive in!
📊 1. Setting Up the Dataverse Table
We start with a Dataverse table named Case Document having the following columns:
🔹 Case Number (AutoNumber)
🔹 Title (Text)
🔹 File (File data type – where uploaded documents are stored)
Our goal is to preview file names in a Canvas App and provide a button to download the file.
🖼️ 2. Displaying Files in PowerApps Gallery
In the PowerApps Canvas App:
- Add a Vertical Gallery
- Set its data source to the
Case Documenttable - Show:
ThisItem.CaseNumberfor the Case IDThisItem.File.FileNamefor the file name
🔧 Use the dot operator (.) to access file properties like FileName and Value.
⬇️ 3. Creating the Download Button
Add a Download Icon/Button next to each file.
In its OnSelect property, use:
Download("YOUR_WEB_API_URL_HERE")
To find the Web API URL, go to the record in Dataverse, right-click the file, and copy the link.
But this is a static link! Let’s now make it dynamic 👇
🔗 4. Constructing the Dynamic Web API URL
The pattern for the URL is:
<environment_url>/api/data/v9.0/<plural_table_name>(<GUID>)/<column_name>/$value
To construct this dynamically:
Download("https://<env>.crm.dynamics.com/api/data/v9.0/case_documents(" & ThisItem.case_documentid & ")/file_column/$value")
Replace case_documents, case_documentid, and file_column with your actual table and column names.
🧠 5. Making the Environment URL Dynamic
Instead of hardcoding the environment URL, use an Environment Variable:
🔸 Go to Power Apps > Solutions
🔸 Create a new Environment Variable (e.g., EnvironmentURL)
🔸 Set its current value to your environment URL
Then, in PowerApps, connect to:
✔ Environment Variable Definitions
✔ Environment Variable Values
Use this Power Fx to retrieve the environment URL dynamically:
LookUp(
'Environment Variable Values',
'Environment Variable Definition'.'Display Name' = "EnvironmentURL"
).Value
Combine it with your download URL logic using string concatenation.
✅ 6. Final Test
Now, clicking the download icon on any file:
✔ Dynamically constructs the API URL
✔ Downloads the file instantly
✔ Works across environments with no hardcoding
👏 Success!