Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

norwegian char problem

(0) ShareShare
ReportReport
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,445 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!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans