X++ code to read CSV files in Dynamics 365 for operations

Reading data from csv files is a very common development requirement for X++ developers. In Dynamics 365 for operations there are some interesting concepts, as opposed to AX2012. The application runs on cloud and the client is in web. In such scenarios the way to read files from local system is a 2 step process.
Step 1: Upload the file from local machine to Microsoft cloud (Azure) storage space called as Azure blob.
Step 2: Read the file from Azure blob to retrieve the data.
Microsoft has done an excellent job in creating out of the box classes to run this logic. So we are not required to re-invent the wheel and can leverage the existing API\’s. The below X++ code can be used to read a CSV file:



The standard API\’s are used here do the required magic. I have tried to breakdown the functionality of the calls.
Step 1 is done by the below command where the file is uploaded from local machine to azure blob

Step 2 is done by opening the IO stream from the Blob and reading it from the IO class


Rest of the job is almost similar to AX2012 pattern.

To test the job we create a sample csv file

On running the job a file picker will be shown, where you can browse the file.

The progress of uploading it to cloud space is shown in the progress bar

Infolog is shown with the data on the file


Worth mentioning that there are various other IO classes, provided out of the box which have the below associations

The file upload classes have different strategies and the below classes are available out of the box. For more information refer to nice articles mentioned in the references:

To quickly reuse the code here it goes

class RGReadSample

    /// Runs the class with the specified arguments.

    /// The specified arguments.
    public static void main(Args _args)
        AsciiStreamIo                                   file;
        Array                                           fileLines;
        FileUploadTemporaryStorageResult                fileUpload;
        fileUpload = File::GetFileFromUser() as FileUploadTemporaryStorageResult;
        file = AsciiStreamIo::constructForRead(fileUpload.openResult());
        if (file)
            if (file.status())
                throw error(\”@SYS52680\”);


        container record;
        while (!file.status())
            record = file.read();

            if (conLen(record))
                info(strFmt(\”%1 – %2\”,conPeek(record,1),conPeek(record,2)));



Feel free to comment on any feedback/suggestions in case I have missed any important part of this framework  but this code works nicely on reading csv files. Thanks for reading the blog and have a great day.

More references:


6 Replies to “X++ code to read CSV files in Dynamics 365 for operations”

  1. Anonymous says:

    Hi,you post helps a lot!!! Could you please share the procedure to export and import data to word document using X++ like in AX 2012


  2. Anonymous says:

    How would you handle let's say, a directory that contains 100+ files? I found all this interactive stuff for a single file, nothing for processing multiple files.Thanks.


  3. Anonymous says:

    I get a cancel button on the form that opens up, I get an error message when I click on cancel button as \”object reference not set to an instance of an object\”I need to close this form on click of cancel button.Please help


  4. Anonymous says:

    I get a \”Cancel\” button on the form that pops up, I get error as \”Object reference not set to an instance of an object.\”. I need to close that form on click of cancel.Please help.


  5. Atul Jain says:

    while importing the CSV file through this code but not getting OK button on the screen.


  6. Atul Jain says:

    while importing the CSV file through this code but not getting OK button on the screen.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

A WordPress.com Website.
%d bloggers like this: