How to create text file using C/AL Code

I need to create a text file using C/AL code in Dynamics 365 Business Central hosted version. Where can I find an example or documentation on the best practice for creating text or csv files in C/AL Code?

Answers

  • ftorneroftornero Member Posts: 524
    In fact it's AL code.

    Here it's an option that download a txt file with 3 lines.
    codeunit 50102 GBS_CreateFile
    {
        trigger OnRun()
        begin
            
        end;
        
        procedure GBS_CreateTxtFile(FileName: Text)
        var
    
            InStr: InStream;
            OutStr: OutStream;
            tmpBlob: Record TempBlob temporary;
            CR: char;
            LF: char;
    
        begin
            CR := 13;
            LF := 10;
            tmpBlob.Blob.CreateOutStream(OutStr);        
            OutStr.WriteText('First line'+ CR + LF);
            OutStr.WriteText('Second line'+ CR + LF);
            OutStr.WriteText('Third line'+ CR + LF);        
            tmpBlob.Blob.CreateInStream(InStr);
            DownloadFromStream(InStr, '', '', '', FileName); 
        end;
      
    }
    


    Regards.
Sign In or Register to comment.