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());
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;
}
*This post is locked for comments
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
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.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,219 Super User 2024 Season 2
Martin Dráb 230,056 Most Valuable Professional
nmaenpaa 101,156