web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Text with special characters NAV 2016,

(0) ShareShare
ReportReport
Posted on by

Hi everyone I need help :(  and really sorry for my bad english,

I have the next scenario.
I have to make a Electronic invoice for Mexico, but the Invoice need have a special characters, example Biciclá-ta , Silla inv. PARÍS, negra,I save my text in a blob file, then i read this blob and storage her content in a bigtext, and finaly I read char by char to save the string in my txt with all the string.
My code

VATFILE.CREATEOUTSTREAM(ostre2);
SalesInvHeader.CALCFIELDS(SalesInvHeader."Original String");
SalesInvHeader."Original String".CREATEINSTREAM(Instr);
VarBig.READ(Instr);
FOR I:=1 TO VarBig.LENGTH DO
BEGIN
VarBig.GETSUBTEXT(VarText,I,1);
//NewText:= Ascii2Ansi.Ascii2Ansi (VarText);
ostre2.WRITETEXT(VarText);
END;
VATFILE.CLOSE;
Download.DownloadToFile(TempFile+'\cfdi.txt',LocationCadena + '\cfdi.txt');




as will you see, i can try use Ascii2Ansi function but dont work correctly, also I try use TEXTENCODING but don't work too.
My txt have this:
Biciclÿ-ta
PAR„S

Note
I make a simple Electronic invoice with 6 lines and i dont have problem, but later i try make the same invoice but now with 16 o more productos and don't work :(

AND again sorry for my terrible terrible englihs, i hope understand my problem :smile:

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    use Stream Reader for UTF8 like below

    SalesInvHeader."Original String".CREATEINSTREAM(Instr);

    streamReader := streamReader.StreamReader(Instr,Encoding.UTF8,TRUE);
    FullText := streamReader.ReadToEnd();

    FullText is of DataType Text

    StreamReader is of DataType DotNet (System.IO.StreamReader.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')

    Encoding is of DataType DotNet (System.Text.Encoding.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')

  • Community Member Profile Picture
    on at

    I dont have any class in the .NET Type List

    NET-LIST.png

    who i need to install the System.TextEnconding?

    Thank you so much for the answer

  • Suggested answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    When you declare variable as DotNet in .NET Tab first select mscorlib then you will have the functions available.

  • Community Member Profile Picture
    on at

    Hi Suresh Kulla, sorry but dont work this method, I obtain this

    Ciudad de M?xico  - México

    Sill­-n   -   Sillín

    Any idea why this happend

    This is my code

    VATFILE.CREATEOUTSTREAM(ostre2);

    SalesInvHeader.CALCFIELDS(SalesInvHeader."Original String");

    SalesInvHeader."Original String".CREATEINSTREAM(Instr);

    StreamReader:= StreamReader.StreamReader(Instr,Encoding.UTF8);

    Fulltext:=StreamReader.ReadToEnd();

    //VarBig.READ(Instr);

    //Cadeaaaaa:=FORMAT(VarBig);

    //FOR I:=97 TO VarBig.LENGTH DO

     //BEGIN

      //VarBig.GETSUBTEXT(VarText,I,1);

      //NewText:= Ascii2Ansi.Ascii2Ansi (VarText);

    ostre2.WRITETEXT(Fulltext);

  • Suggested answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    When you print FullText by using MESSAGE what is displayed ?

  • Community Member Profile Picture
    on at

    The Fulltext show this

    Characters2.png

    I try with my same code, Using the BigText and the for loop, assing the char by char to the FullText, y after print the menssage I obtain that

    VarBig.READ(Instr);
    FOR I:=97 TO VarBig.LENGTH DO
      BEGIN
        VarBig.GETSUBTEXT(VarText,I,1);
        //NewText:= Ascii2Ansi.Ascii2Ansi (VarText);
        Fulltext:= Fulltext + VarText;
        //MESSAGE(Fulltext);
        
    END;
    MESSAGE(Fulltext);
    ostre2.WRITETEXT(Fulltext);


    Characters2.png

    But in my txt I have

    M‚xico, Tlaxcala|AIO940307RG7|Automatizaciones Industriales y de Oficina de Tlax|Av. Promocion # 120 Zo¥a Industrial|Puebla|Ciudad de M‚xico|Ciudad de M‚xico|Tlaxcala|MX|90300|Av. Promocion # 120 Zo¥a Industrial|Puebla|Ciudad de M‚xico|Tlaxcala|MX|90300|regimen general de personas morales|CON8411306M7|Pruebas1|5 de mayo|Centro|Ciudad de M‚xico|MX|01030|4|UDS|1980-S|Silla giratoria MOSCð, roja|1711.00|6844.00|6|UDS|1900-S|Silla inv. PARäS, negra|1735.00|10410.00|45|UDS|1850|Sill¡n|1234.00|55530.00|IVA|0.00|0.00|IVA|15.00|10917.60|10917.60||


    I think maybe the problem is in the "Outstream.Writetext Function",

  • Suggested answer
    keoma Profile Picture
    32,729 on at

    you need to work with unicode.

    for that follow blogs.msdn.microsoft.com/.../reading-and-writing-unicode-files-using-cal

  • Verified answer
    Community Member Profile Picture
    on at

    Thanks for answer jonathan, but I try it and not result ,maybe its my PC o maybe the NAV, I dont know but finally i make a component in Visual to read and save the txt whit speacial characters, thank to you and thanks Suresh for yours answers

  • Community Member Profile Picture
    on at

    I just want to make it more clear than above guideline:

    When writing to BLOB field, Unicode Encoding have to be involved in order to ensure later Reading is going well or ??? char will take the replacement:

    StreamWriter: System.IO.StreamWriter.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    // Writing part

    ...

    BigTextVar.ADDTEXT('Your Unicode Text going here!');

    Record.CALCFIELDS(BlobField);

    CLEAR(BlobField);

    Record.BlobField.CREATEOUTSTREAM(OutStreamVar);

    StreamWriter := StreamWriter.StreamWriter(OutStreamVar, Encoding.Unicode);

    StreamWriter.Write(BigTextVar);

    StreamWriter.Flush();

    StreamWriter.Close();

    ...

    // Reading part

    ...

    Record.CALCFIELDS(BlobField);

    Record.BlobField.CREATEINSTREAM(InStreamVar);

    StreamReader := StreamReader.StreamReader(InStreamVar, Encoding.Unicode);

    BigTextVar.ADDTEXT(StreamReader.ReadToEnd());

    ...

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans