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!
TempBlob: record TempBlob.
REPORT.SAVEAS(206, TempText, REPORTFORMAT::Pdf, OutS);
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';
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.
Thank you very much! It works now.