Reading Unicode & Normal Text File

lakshanvindana
Member Posts: 79
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.
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
ERP Consultant - MS Dynamics NAV
https://lk.linkedin.com/pub/lakshan-vindana-kulawansa/37/2a2/592
0
Comments
-
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.0 -
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/5920 -
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 - ArcherPoint0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions