CSV import is not working for UTF-8 encoding files

Hi Experts,

I have issue that my code is behaving strange that, if I import CSV UTF-8 file its completely behaving strange and taking wrong records. Its working only on Coma delimited file.

AsciiStreamIo file;
Array fileLines;
FileUploadTemporaryStorageResult fileUpload;
Counter counter = 0;

boolean                             header = true;
#OCCRetryCount;

try
{
    //Upload a file
    fileUpload  = File::GetFileFromUser(classStr(CSVFileUploadTemporaryStorageStrategy));
    file        = AsciiStreamIo::constructForRead(fileUpload.openResult());
         
    if (file)
    {
        if (file.status())
        {
            throw error("@SYS52680");
            
        }
        file.inFieldDelimiter(','); //separator
        file.inRecordDelimiter('\r\n');
    }

    //Read a CSV File
    container rec;
    ttsbegin;

while(file.status() == IO_Status::Ok)
//while (!file.status())
{
counter++;
rec = file.read();
if (conLen(rec))
{
if(header == true)
{
header = false; //This CSV file will always have header
continue;

            }
      //My code
       info("Import Completed");
        ttscommit;

Could you all please guide me on this issue.

Thanks,
Mark

If you want to use UTF-8, the bug is that you’re using AsciiStreamIo class. As the name suggests, it’s for ASCII encoding. Use CommaTextStreamIo class instead.

You said it works for “Coma delimited file” (without mentioning any encoding), but not “CSV UTF-8 file”. Because CSV means Comma-Separated Values, I guess it’s the same thing that you mean by “Coma delimited file” and the only difference is in encoding. Correct me if you actually mean something else.

Perfect. Thanks @MartinDrab .

Thanks,
Mark