How do I make an ANSI file on a FTP server?

MortenSteengaardMortenSteengaard Member Posts: 136
Hi experts,

This is in Axapta 2009.

I have the code below, that can make an utf-8 file on a FTP server with username and password. That works fine.

The only problem is that I need to save the file as ANSI, so the Danish letters are correct.

In the Axapta 2009 program, I make an ANSI file in the Windows temp folder. That file is correct, but when I use the code below to send it to the FTP server, the Danish letters get wrong.

I hope you can help!

Best regards,

Morten

public void uploadFiletoFTPServer(str _fileNameTmp, str _fileNameFtp)
{
    System.Object request,response,credential;
    System.IO.StreamReader streamReader;
    System.IO.Stream requestStream;
    System.Array files;
    System.Net.FtpWebRequest ftpRequest;
    System.Net.FtpWebResponse ftpResponse;
    System.Byte[] bytes;
    System.Text.Encoding myEncoding;
    System.Exception sysException;
    Str 120 TempPath,executedate;
    str timeinstr,nextFile;
    Commaio file;
    container line;
    Filename filepath,fileType, ftpFileName;
    System.Net.ICredentials iCredentials;
    System.Net.IWebProxy    iWebProxy;
    ;
    try
    {
        ftpFileName = "ftp...//myFile";
        streamReader = new System.IO.StreamReader(_fileNameTmp);
        // must be ANSI:
        myEncoding = System.Text.Encoding::get_UTF8();
        //myEncoding = System.Text.Encoding::get_Default();
        //myEncoding = System.Text.Encoding::get_Unicode();
        //myEncoding = System.Text.Encoding::GetEncoding(1252);
        //myEncoding = System.Text.Encoding::get_ASCII();
        //myEncoding = System.Text.Encoding::get_BigEndianUnicode();
        //myEncoding = System.Text.Encoding::GetEncoding(865);
        //myEncoding = System.Text.Encoding::GetEncoding(65001);
        bytes = myEncoding.GetBytes(streamReader.ReadToEnd());
        
        streamReader.Close();
        request = System.Net.WebRequest::Create(new System.Uri(ftpFileName));
        ftpRequest = request;
        credential = new System.Net.NetworkCredential("myUserId", "myPassword");
        iCredentials = credential;
        ftpRequest.set_Credentials(iCredentials);
        ftpRequest.set_ContentLength(bytes.get_Length());
        ftpRequest.set_Method("STOR");
        requestStream = ftpRequest.GetRequestStream();
        requestStream.Write(bytes,0,bytes.get_Length());
        requestStream.Close();
        response = ftpRequest.GetResponse();
        ftpResponse = response;
    }
    catch(Exception::CLRError)
    {
        sysException = CLRInterop::getLastException();
        info(sysException.get_Message());
    }
    CodeAccessPermission::revertAssert();
}
Sign In or Register to comment.