X++ Upload and Download file - D365 FO
class RetailSharedParameters_Eventhandlers
{
/// <summary>
/// Event handler for the "UploadFile" button click event.
/// </summary>
/// <param name="sender">The form control that triggered the event.</param>
/// <param name="e">Event arguments.</param>
[FormControlEventHandler(formControlStr(RetailSharedParameters, UploadFile), FormControlEventType::Clicked)]
public static void UploadFile_OnClicked(FormControl sender, FormControlEventArgs e)
{
// Get the button that triggered the event
FormButtonControl callerButton = sender as FormButtonControl;
// Get the form run instance
FormRun form = callerButton.formRun();
// Get the data source for the RetailSharedParameters table
FormDataSource RetailSharedParameters_ds = form.dataSource(formDataSourceStr(RetailSharedParameters, RetailSharedParameters)) as FormDataSource;
// Get the current record from the data source
RetailSharedParameters RetailSharedParameters = RetailSharedParameters_ds.cursor();
// Prompt the user to upload a file
FileUploadTemporaryStorageResult result = File::GetFileFromUser() as FileUploadTemporaryStorageResult;
// Check if the file upload was successful
if (result && result.getUploadStatus())
{
// Store the file name and download URL in the table
RetailSharedParameters.FileName = result.getFileName();
RetailSharedParameters.SoundFile = result.getDownloadUrl();
// Save the changes to the database
RetailSharedParameters.write();
}
}
/// <summary>
/// Event handler for the "DownloadFile" button click event.
/// </summary>
/// <param name="sender">The form control that triggered the event.</param>
/// <param name="e">Event arguments.</param>
[FormControlEventHandler(formControlStr(RetailSharedParameters, DownloadFile), FormControlEventType::Clicked)]
public static void DownloadFile_OnClicked(FormControl sender, FormControlEventArgs e)
{
// Variable to store the file URL
str fileUrl = '';
// Get the button that triggered the event
FormButtonControl callerButton = sender as FormButtonControl;
// Get the form run instance
FormRun form = callerButton.formRun();
// Get the data source for the RetailSharedParameters table
FormDataSource RetailSharedParameters_ds = form.dataSource(formDataSourceStr(RetailSharedParameters, RetailSharedParameters)) as FormDataSource;
// Get the current record from the data source
RetailSharedParameters RetailSharedParameters = RetailSharedParameters_ds.cursor();
// Retrieve the stored file URL
fileUrl = RetailSharedParameters.SoundFile;
// Open the file URL in a browser
if (fileUrl)
{
new Browser().navigate(fileUrl);
}
else
{
// Notify the user if no file URL is found
warning("No file URL found.");
}
}
}Published on:
Learn moreRelated posts
Overview Quality Management in Microsoft Dynamics 365 Finance & Operations – Part 1
Why Every Manufacturing Business Needs Quality Management Overview Why Every Manufacturing Business Needs Quality Management Imagine walking i...
X++ Show Cross-Reference With Read/Write field reference
New release of TRUDUtilsD365 Developer Add-in that includes an advanced Cross-references form, allowing you to see the actual X++ code and det...
Support Parallel Processing for Archive Jobs in Dynamics 365 Finance and Operations
We’re pleased to introduce a new capability for Dynamics 365 Finance and Operations archive with Dataverse long-term retention: parallel proce...
D365FO License usage log utility
Learn how the new D365FO licensing model works and discover an open-source X++ utility to monitor actual user activity and optimize your licen...
Implement Service-based integration in D365FO
This blog post describes how to implement a synchronous integration with D365FO by creating a service using the External Integration framework...
Sync data from Dynamics 365 Finance & Operations Azure SQL Database (Tier2) to local SQL Server (AxDB)
A new utility to synchronize data from D365FO cloud environments to local AxDB, featuring incremental sync and smart strategies.
Action ‘Update_a_record’ failed: An error has occurred. No resources were found when selecting for update – Fixing Cross-Company Update Issues in Finance & Operations Using Dataverse Virtual Entities (Power Automate)
Recently, while trying to update the Projects table in Finance & Operations using the Fin & Ops Apps actions in Power Automate, we ran...
Simplifying License Management for Dynamics 365 Finance and Operations: Improved User License Validation
Microsoft is updating the timeline for in-app notifications and per-user license validation to give customers more time to prepare. To enable ...
Simplifying License Management for Dynamics 365 Finance and Operations: Improved User License Validation
In-product notifications and user subscription license (USL) validation has been amended for customers in FY25 Q4, FY26 Q1 renewals. Microsoft...