Options

Upload several .csv files

mtsamtsa Member Posts: 2
Hi! I'm working with Business Central 19.0 (cloud).

I am trying to import .CSV files with CSVBuffer and UploadIntoStream function.
The problem is that I need upload several files at the same time, one behind the other, but UploadIntoStream just let you choose one file.

I would like to be able to select a location and have all the files processed, it is possible? How?

Thanks

Answers

  • Options
    txerifftxeriff Member Posts: 492
    I didnt know MS added CSV buffer, lol.

    You usually can use an XMLport and set

    Format = VariableText;
    FieldSeparator = ',';
    Encoding = UTF8; //I usually set and save csv files as utf.

    then you just do a code loop like:
    //"initialise"
    CLEAR(FileRec);
    FileRec.SETCURRENTKEY(Path,"Is a file",Name);
    FileRec.SETRANGE(Path,'C:\temp\');
    IF FileRec.FINDFIRST THEN ;
    
    CLEAR(FileRec);
    
    FileRec.SETRANGE(Path,'yourfilepath');
    FileRec.SETRANGE("Is a file",TRUE);
    FileRec.SETFILTER(Name,'filename*'); //'%1*' doesnt work
    IF FileRec.FINDSET THEN REPEAT
      CLEAR(X50016);
      vFileVar.OPEN(FileRec.Path+FileRec.Name);
      vFileVar.CREATEINSTREAM(vInStr);
      X50016.SETSOURCE(vInStr);
      X50016.IMPORTFILE(TRUE);
      X50016.IMPORT;
      vFileVar.CLOSE;
    UNTIL FileRec.NEXT=0;
    
  • Options
    samantha73samantha73 Member Posts: 96
    I found CSV buffer too limiting and now use XMLport
Sign In or Register to comment.