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

MortenSteengaard
Member Posts: 144
in Dynamics AX
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();
}
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();
}
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions