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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
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

I have the same question (0)
  • Martin Dráb Profile Picture
    239,985 Most Valuable Professional on at

    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.

  • kabir Profile Picture
    80 on at

    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

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans