A question received today was the following: is it possible from my extension in Dynamics 365 Business Central asking a user to select a local CSV file, load it and then managing the content accordingly to my business needs using CSV Buffer table?
In standard NAV code (C/AL) you can use CSV Buffer table to load a CSV file (without using an XMLPort) and then parsing its content line by line. You can load a CSV file by using the following C/AL code:
And what about AL code? Can I use CSV Buffer in my extension for Dynamics 365 Business Central (SaaS)? The answer is yes, but the way you read the file is different. If you try to use the LoadData method, this is the result:
Here you’re in the cloud and you need to use Streams for accessing files. This is the code that works in a cloud Dynamics 365 Business Central environment:
The key here is to create an InStream object, reading the CSV file to the InStream object and then call the LoadDataFromStream method of the CSV Buffer table. Then you can parse the CSV content exactly like on the old C/AL code.