Events
Mar 31, 11 PM - Apr 2, 11 PM
The ultimate Microsoft Fabric, Power BI, SQL, and AI community-led event. March 31 to April 2, 2025.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
This .NET 6.0 sample demonstrates how to perform operations with file columns using the Dataverse Web API.
This sample uses the common helper code in the WebAPIService class library (C#).
Clone or download the PowerApps-Samples repository.
Open the PowerApps-Samples\dataverse\webapi\C#-NETx\FileOperations\FileOperations.sln
file using Visual Studio 2022.
Edit the appsettings.json
file to set the following property values:
Property | Instructions |
---|---|
Url |
The Url for your environment. Replace the placeholder https://yourorg.api.crm.dynamics.com value with the value for your environment. See View developer resources to find this. |
UserPrincipalName |
Replace the placeholder you@yourorg.onmicrosoft.com value with the UPN value you use to access the environment. |
Password |
Replace the placeholder yourPassword value with the password you use. |
Save the appsettings.json
file
Select which of the projects you want to run in solution explorer. Right click the project and choose Set as Startup Project.
Press F5 to run the sample.
The output of the sample should look something like this:
Creating file column named 'sample_FileColumn' on the account table ...
Created file column named 'sample_FileColumn' in the account table.
Created account record with accountid:5fb4f993-7c55-ed11-bba3-000d3a9933c9
Uploading file Files\25mb.pdf ...
Uploaded file Files\25mb.pdf
Downloading file from accounts(5fb4f993-7c55-ed11-bba3-000d3a9933c9)/sample_filecolumn ...
Downloaded the file to E:\GitHub\PowerApps-Samples\dataverse\webapi\C#-NETx\FileOperations\FileOperationsWithActions\bin\Debug\net6.0//downloaded-25mb.pdf.
Deleted the file using FileId.
Deleted the account record.
Deleting the file column named 'sample_filecolumn' on the account table ...
Deleted the file column named 'sample_filecolumn' in the account table.
This sample is a solution with three projects. Each project performs the same operations in a different manner. See the respective README files for details on each project.
The code for each project is in the respective Program.cs
file.
Each project uses a shared Utility
class to perform common operations. This class is in the Utility.cs file.
At a high level, each project performs these operations:
The Utility.CreateFileColumn
function creates a file column named sample_FileColumn
in the account table with a MaxSizeInKb
value of 10 MB.
The Utility.UpdateFileColumnMaxSizeInKB
function updates the MaxSizeInKb
value of the sample_FileColumn
file column to 100 MB.
Tip: If you want to create some error scenarios because the file column size is too small, comment out this line.
The Utility.GetFileColumnMaxSizeInKb
retrieves the MaxSizeInKb
value of the sample_FileColumn
file column and stores it in a variable named fileColumnMaxSizeInKb
.
Before a file can be uploaded to the file column, a record must exist.
The function to upload the file accepts a parameter named fileColumnMaxSizeInKb
and uses that value to test the size of the file. If the file is larger than the configured limit of the file column, it will throw an error.
If the file upload succeeded, the function to download the file will save it to the current directory. You can try opening the file to confirm it was uploaded and downloaded correctly.
If the file upload succeeded, the file is deleted.
To leave the system in the state before the sample ran, it does the following:
Use file column data
Sample: File Operations using Dataverse SDK for .NET
Use image column data
Sample: Image Operations using Dataverse Web API
Events
Mar 31, 11 PM - Apr 2, 11 PM
The ultimate Microsoft Fabric, Power BI, SQL, and AI community-led event. March 31 to April 2, 2025.
Register today