Reading Unicode & Normal Text File

Hi All,

My question is very simple, is it possible to read Unicode text file and normal text file using a one method (CAL Code)?
Version : 2013

Further details:
I read a normal text file in a report, using following method. It works fine.
code
Variables;
name = TextFile data type = File
name = TextLine data type = Text

TextFile.OPEN(TextFileName);
TextFile.READ(TextLine);
code

Then I read a Unicode text file in a report, using following method (because of a client requirement). It works fine.
code
Variables;
name = ReadStream data type = InStream
name = StreamReader data type = DotNet
name = Encoding data type = DotNet


TextFile.CREATEINSTREAM(ReadStream);
StreamReader := StreamReader.StreamReader(ReadStream, Encoding.Unicode);
TextLine := StreamReader.ReadLine;
code

But, a normal text file cannot be read using the method I used for Unicode method.
I need to know, is there a method, which can use to read both normal & Unicode text files.

Thank you.
Lakshan Kulawansa
ERP Consultant - MS Dynamics NAV
https://lk.linkedin.com/pub/lakshan-vindana-kulawansa/37/2a2/592

Comments

  • nthalagalanthalagala Member Posts: 2
    edited 2016-04-28
    Hi Lakshan,

    You can just use the DotNet interop and the standard Stream functionality, where you can set any encoding you want...

    In your code use it as, select ASCII from the encoding properties.
    StreamReader := StreamReader.StreamReader(ReadStream, Encoding.ASCII);

    It works fine for me. Either you use ASCII or UNICODE encode text files.
  • lakshanvindanalakshanvindana Member Posts: 79
    it is working with "Encoding.ASCII" for Unicode & normal text files.

    Thank you.
    Lakshan Kulawansa
    ERP Consultant - MS Dynamics NAV
    https://lk.linkedin.com/pub/lakshan-vindana-kulawansa/37/2a2/592
  • kylehardinkylehardin Member Posts: 257
    I've never tried it, but if you have the XMLPort defined as a variable, you can set the property TEXTENCODING on the xmlport itself and avoid having to use DotNet.
    Kyle Hardin - ArcherPoint
Sign In or Register to comment.