Hi all
I have an issue when writing a file. I try to write the file in textencoding::WINDOWS(Ansi), but end up having encoding "UCS-2 Little Endian" when I open the file in Notepad++
Here is my code:
LOCAL SaveToFilePath(FileContent : Text;RecordRef : RecordRef)
FieldRef := RecordRef.FIELD(3);
IF ISSERVICETIER THEN BEGIN
TempFile.CREATETEMPFILE(TEXTENCODING::Windows);
TempFile.CREATEINSTREAM(inStream);
Counter := 1;
REPEAT
Text := COPYSTR(FileContent, Counter,1);
TempFile.WRITE(Text);
Counter += 1;
UNTIL Counter > STRLEN(FileContent);
FileTo := FORMAT(FieldRef.VALUE)+'.txt';
FileName := FileTo;
// Tranfer the content from the temporary file on the NAV server to a file on the RoleTailored client.
DOWNLOADFROMSTREAM(
inStream,
'Save File to RoleTailored Client',
FileMgt.Magicpath,
'Text File *.txt| *.txt',
FileTo);
// Close the temporary file and delete it from NAV server.
TempFile.CLOSE();
END;
FileMgt.MoveFile(FileTo,ConsignorSetup."File Path"+FileName);
*This post is locked for comments
Thanks for the link Nareshwar!
For those interested I rewrote the code to use .net streamwriter an encoding.default which in this case is a type of ANSI
FieldRef := RecordRef.FIELD(3);
IF ISSERVICETIER THEN BEGIN
TempFile.CREATE('C:\Temp\ConsignorTempFile.wfd'); //
TempFile.CREATEOUTSTREAM(outStream);
streamWriter := streamWriter.StreamWriter(outStream, encoding.Default);
streamWriter.WriteLine(FileContent);
streamWriter.Close;
TempFile.CLOSE();
FileTo := FORMAT(FieldRef.VALUE)+'.wfd';
FileName := FileTo;
DOWNLOAD(
'C:\Temp\temp.txt',
'Save File to RoleTailored Client',
FileMgt.Magicpath,
'Text File *.wfd| *.wfd',
FileTo);
END;
FileMgt.MoveFile(FileTo,ConsignorSetup."File Path"+FileName);
ERASE('C:\Temp\ConsignorTempFile.wfd');
Hi,
I am not sure how accurate Notepad++ is.
Check this link: programmers.stackexchange.com/.../how-to-detect-the-encoding-of-a-file
Hope it helps.
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,113 Super User 2024 Season 2
Martin Dráb 229,918 Most Valuable Professional
nmaenpaa 101,156