Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

norwegian char problem

Posted on by 80

 

Hi,

I am retrieving a file and sending it through FTP but norwegian char(ø å æ) does not work.

used .NET in x++.

Most probably the problem is in the function get_UTF8() .I tried other function too but nothing is working.

 

 reader = new System.IO.StreamReader(localFileNameAndPath);

     utf8 = System.Text.Encoding::get_UTF8();

    fileContent = utf8.GetBytes(reader.ReadToEnd());

Below there is a  whole code:

 

 

server static boolean putFileToServer(AHL_eduTransportSpesification transSpec, str localFileNameAndPath, str serverFileName)

{

    boolean                         fileOK = true;

    object                          ftpRequest;

    object                          ftpResponse;

 

    System.IO.StreamWriter          TextWriter;

 

    System.IO.StreamReader          reader;

    System.IO.Stream                requestStream;

    System.Net.FtpWebRequest        request;

    System.Net.FileWebResponse      response;

    System.Net.NetworkCredential    credential;

    System.Exception ex;

 

    InteropPermission               perm;

    FileIOPermission                IOPerm;

 

    System.Byte[]                   fileContent;

    ASCIIIO                         fileOut,fileInn;

 

    System.Text.Encoding            utf8;

    Container con;

    str s;

    int num;

    str ch;

;

 

   perm = new InteropPermission(InteropKind::ClrInterop);

   perm.assert();

    reader = new System.IO.StreamReader(localFileNameAndPath);

     utf8 = System.Text.Encoding::get_UTF8();

    fileContent = utf8.GetBytes(reader.ReadToEnd());

 

    reader.Close();

 

    CodeAccessPermission::revertAssert();

    perm = new InteropPermission(InteropKind::ClrInterop);

    perm.assert();

    try

    {

 

        ftpRequest = System.Net.WebRequest::Create("ftp://" + transSpec.FTPServerName + "/" + transSpec.FTPDirectory + "/" + serverFileName );

        request = ftpRequest; // Eneste mÃ¥te Ã¥ omgÃ¥ casting pÃ¥.

 

        credential = new System.Net.NetworkCredential(transSpec.FTPUserName, transSpec.FTPPassword);

        request.set_Credentials(credential);

        request.set_ContentLength(fileContent.get_Length());

        request.set_Method("STOR");

 

        requestStream = request.GetRequestStream();

        requestStream.Write(fileContent,0,fileContent.get_Length());

        requestStream.Close();

 

        ftpResponse = request.GetResponse();

        response = ftpResponse;

    }

    catch (Exception::CLRError)

    {

        ex = CLRInterop::getLastException().GetBaseException();

        error(ex.get_Message());

    }

    CodeAccessPermission::revertAssert(); 

    return fileOK;

}

Thank you
kabir

 

*This post is locked for comments

  • kabir Profile Picture
    kabir 80 on at
    Re: norwegian char problem

    make it simple.

    reader = new System.IO.StreamReader(localFileNameAndPath);

       utf8 = System.Text.Encoding::get_UTF8();

       fileContent = utf8.GetBytes(reader.ReadToEnd());

       reader.Close();

    From above , I am reading a file and for example my first char is Ã…    

    SO,

       ch = fileContent.GetValue(0);

       print  fileContent.GetValue(0); // wrong value here

       print num2char(ch);  // strange char.  should be Ã…

       print  char2num('Ã…',1) // should be this value

    How can I get the correct value  in  fileContent.GetValue(0)??

    I tried UTF8 and other function those are available..

    If anyone have any clue please help.

    Thanx

    kabir

  • Martin Dráb Profile Picture
    Martin Dráb 230,056 Most Valuable Professional on at
    Re: norwegian char problem

    Hi, could you please write a bit more about what are you doing? I don't believe that anybody can help you based on this information.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,219 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans