Thursday, 7 October 2010

Writing to a CSV in Microsoft Dynamics AX 2009 X++

This post has moved to my new website, if not redirected automaticaly please click here: https://anthonyblake.github.io/ax2009/2010/07/10/ax2009-write-csv.html 

To write to a csv in Microsoft Dynamics AX 2009 X++

//Macros
#File

//File Access Vars
FileIOPermission permission;
CommaTextIO commaio;
FilePath filePath = @'C:\MyFolder\MyOutput.csv';
;

//Set Write Permission For New File
permission = new FileIOPermission(filePath, #io_write);
permission.assert();

//Create CommaIO Object
commaio = new CommaTextIO(filePath, #io_write);

//You Might Want The Next Line To Go In A Loop
commaio.write('Field1', 'Field2', 'Field3', 'etc...etc');

//After Your Loop...
//This Line Isn't Always Needed But Releases
// The Lock On The Output File If It Is To Be Moved
commaio = null;

//Reset Write Access
CodeAccessPermission::revertAssert();

No comments:

Post a Comment

Thanks for the feedback!