Hi experts,
in NAV 2016 I have made a web service codeunit that creates a pdf file in the temp folder.
After DOWNLOADFROMSTREAM, I try to copy the file to another folder, but I get the error (manually translated): "The user does not have the required permission or the path is write protected".
I guess, I need to close a file or a stream, but cannot find the right one.
It works fine, if I copy any other files to the folder, that gives the error. So it must be something with the temp file.
Here is my code. Hope you can help!
var:
TempBlob: record TempBlob.
InS: Instream
OutS: OutStream
TempFileName: Text
EndingFileName: Text
TempBlob.RESET();
TempBlob.Blob.CREATEOUTSTREAM(OutS);
REPORT.SAVEAS(206, TempText, REPORTFORMAT::Pdf, OutS);
TempBlob.INSERT();
TempBlob.CALCFIELDS(Blob);
TempBlob.Blob.CREATEINSTREAM(InS);
TempFileName := 'Invoice.pdf';
DOWNLOADFROMSTREAM(InS,'','<TEMP>', '', TempFileName);
TempBlob.RESET(); // that did not help
CLEAR(InS); // that did not help
CLEAR(OutS); // that did not help
EndingFileName := '\\...\myShare$\' + 'Invoice.pdf';
COPY(TempFileName, EndingFileName);
0
Answers
The problem is that the COPY command is executed in the server side so you must use the codeunit 419 (File Management) and the function CopyClientFile.
Regards.
Thank you very much! It works now.
Best regards,
Morten