Skip to content

How To: Upload a File and Store It in a Table in Microsoft Dynamics Business Central Online - Part 2 of a 4-Part Series How to Upload a file and store it in a table using Microsoft Dynamics 365 Business Central SaaS/Online

At the Microsoft Directions Asia Conference, a team from ArcherPoint attended many sessions and shared their experiences. On a large scale, the conference unveiled the April '19 Release of Dynamics 365 Business Central as well as announcing the end of Windows Client beginning with the October '19 release. They also shared best practices for continuing on with Visual Studio Code and AL.  

In addition, we left the conference with some practical applications. This blog series discusses handling files in Microsoft Dynamics Business Central online, including:

Part 1 explained how to export a file to Excel and then download it. This blog explains how to upload a file and store it in a table.

Uploading a File and Storing It in a Table

A common scenario is to allow users to upload a file to the application. Uploaded files can serve different purposes, like importing data or linking a file to a record. In this example, we are going to upload an Excel file and store it in a table. In the following example, we will use this file as a template to fill with data and then download it to the user.

Prerequisites:

  • Dynamics 365 Business Central Sandbox Environment.
  • Dynamics 365 Business Central should run from Azure Cloud

This task includes the following steps:

  1. Create a table to store the file
  2. Create a list page
  3. Create a function to select and upload an Excel file
  4. Call the function from the list page

Here are the steps:

  1. Create a new table that looks like the table in Figure 1 to store the file. The table will have a BLOB field in which to store the file content.
    Figure 1 – Creating a table in Microsoft Dynamics Business Central online
    Figure 1 – Creating a table in Microsoft Dynamics Business Central online
  2. Create a list page, which will contain the fields and a checkbox to indicate if the BLOB contains a file.
    Figure 2 – Creating a list page in Microsoft Dynamics Business Central online
    Figure 2 – Creating a list page in Microsoft Dynamics Business Central online
  3. Add a function to the table to select and upload an Excel file. In this example, we are using  the File Management Codeunit, which provides functions that are safe for both online and on-premesis.
    Figure 3 – Adding a function in Microsoft Dynamics Business Central online
    Figure 3 – Adding a function in Microsoft Dynamics Business Central online
  4. Call the function from the list page by adding an action to the page that calls the ImportTemplateFile function in the table.
    Figure 4 – Calling a function from the list page in Microsoft Dynamics Business Central online
    Figure 4 – Calling a function from the list page in Microsoft Dynamics Business Central online
  5. Publish the app again, open the Excel Template page, and test the upload function. Use the Order Template.xlsx file from the materials; this file will be used in the next blog in the series, Updating an Existing Excel File.

Stay tuned for the next blog in this series. If you have any Dynamics NAV or Business Central questions for any version, contact ArcherPoint.

Read more "How To" blogs from ArcherPoint for practical advice on using Microsoft Dynamics Business Central or NAV.

If you are interested in NAV/Business Central development, check out our collection of NAV/BC Development Blogs.

    Blog Tags: 
    Read ArcherPoint's Blog Follow us on Twitter Follow us on Facebook Follow us on LinkedIn Link to our RSS feed Watch us on YouTube
    Get Help Now