Copy newly created temp file

MortenSteengaard
Member Posts: 144
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);
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
Best Answer
-
Hello @MortenSteengaard,
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.1
Answers
-
Hello @MortenSteengaard,
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.1 -
Hi ftornero.
Thank you very much! It works now.
Best regards,
Morten0
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