Hi everyone,
I'm doing a developmnet that needs to download a base64 PDF codified from a webService. I call correctly to the WS, and its answer is this one. As you can see. in the node "v1:strEtiquetas" I get the label codified in Base64:
My idea is to save that value in a blob field (sticker) of one of my tables:
For testing that I'm getting all the data correctly, my nex step is to save the PDF in my computer:
But the generated PDF is in blanck, 0kb, empty...
Does anyone see where can I be making any fail?
THnak you very much
Hi aitorNAV,
Try to use TempBlob Record and function FromBase64String to get the file.
Yes, I'm using AL.
Which variable definitions are you asking for?
Type DotNet System.Array.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' lEtiqueta BigText MemoryStream DotNet System.IO.MemoryStream.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' OStream OutStream IStream InStream
ASk for anything you need
Thank you
OK.
So I think you're still coding in development enviroment (C/AL), cause in extension development DotNet isn't allow (only for on-premises extensión)
Add the following Italic line to your code and try again:
ShipHeader.Sticker.CREATEOUTSTREAM(OStream);MemoryStream.WriteTo(OStream);ShipHeader.Registered := TRUE;
Thank you very much, it worked! Really appreciated!
Another question with this issue. My intention is to print the received PDF in a printer. Now, what I'm dping is to download it with this code:
lShipment.Sticker.CREATEINSTREAM(IStream); ToFile :='Sticker.pdf'; DOWNLOADFROMSTREAM(IStream,'','<TEMP>','',ToFile);
But as you will know, this is saveing the PDF into a temp folder, that dissapears when the NAV session is closed. Does exist any way to download it to a folder indicated by me? Or may be, without saving the PDF phisically, to print it directly using the saved blob?
Thank you very much
The DOWNLOADFROMSTREAM function allow you to save the file in a folder in the client side, so you can modify the '<TEMP>' directory for the path you want to save the file.
I think it's better to save the file to a network location for share the file with other users.
Hope this help
Thanks Psice,
What I've tried is to use
lShipment.Sticker.CREATEINSTREAM(IStream); ToFile :='Sticker.pdf'; //DOWNLOADFROMSTREAM(IStream,'','<TEMP>','',ToFile); //descarga silenciosa DOWNLOADFROMSTREAM(IStream,'','C:\XML','',ToFile); //descarga silenciosa
But instead os saving in the indicated path, it opens the dialog window for saving or opening the PDF file
The only way to not get de dialog it's to use the Magic Path (<TEMP>), If you want to save to a specific folder, dialog box always be prompted.
The Magic path is usable out of the stream function, for example, to copy from there to a known path?
Or may be I'm think aboput using the FIle management Codunit. Do you thikn that will be possible with that?
Muchas gracias!
You can try MoveAndRenameClientFile function from File Management codeunit after download the file to magic path.
Hi,
ANd how can I know the path value for the MoveAndRenameClientFile function?
lFileManagement.MoveAndRenameClientFile('<TEMP>','pegatina.pdf','C:\XML\');
This is and old post, but it's quite useful for your request
https://blogs.msdn.microsoft.com/nav/2013/08/09/nav-pattern-of-the-week-silent-file-upload-and-download/
Hello again,
I already try to use the code that found last week on that page, like this:
lShipment.CALCFIELDS(Sticker); lTmpBLob.Blob := lShipment.Sticker; lTempServerFileName := lFileManagement.ServerTempFileName('.pdf'); lFileManagement.DownloadToFile(lTempServerFileName,'c:\XML\pegatina.pdf');
But I find this error:
I'm debuging the development, and the error appears in this pint of the 419 CodeUnit:
Hi AitorNAV,
Well, I think the best option is to use BLOBExport and then MoveAndRenameClientFile.
REally appreciated,
My issue with this is that, as I've said before, can't use '<TEMP'> in the MoveAndRenameClientFile:
lShipment.CALCFIELDS(Sticker); lTmpBLob.Blob := lShipment.Sticker; lTempServerFileName := lFileManagement.ServerTempFileName('.pdf'); lFileManagement.BLOBExportToServerFile(lTmpBLob,lTempServerFileName); lFileManagement.MoveAndRenameClientFile('<TEMP>','pegatina.pdf','C:\XML\')
I get the error "'<TEMP>" file doesn't exist....
Try going to a command line and type ECHO %TEMP% to see if you have a TEMP-variable.But before you do anything With kind of temporary path do you need.IF it is WINDOWS TEMP path then useTempPathVar := ENVIRON('TEMP'); Dynamics NAV temp path
TEMPORARYPATHYou could also use some code to get a temporarypath
Name DataType Subtypeenvironment DotNet System.Environment.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' MESSAGE('%1',environment.GetEnvironmentVariable('TEMP'));
Thanks Palle Arentoft and psice. I've solved this issue with this code:
lShipment.CALCFIELDS(Sticker); lTmpBLob.Blob := lShipment.Sticker; lTempServerFileName := lFileManagement.ServerTempFileName('.pdf'); lFileManagement.BLOBExportToServerFile(lTmpBLob,lTempServerFileName); lFileManagement.DownloadToFile(lTempServerFileName, 'c:\XML\pegatina.pdf');
Thanks again for your tips, realy appreciated!
If you read the link I post before, you can find this piece of code
PROCEDUREDownloadToFile@13(ServerFileName@1002 : Text;ClientFileName@1000 : Text);
VARTempClientFileName@1001 : Text;
BEGINValidateFileNames(ServerFileName,ClientFileName);TempClientFileName := DownloadTempFile(ServerFileName);MoveFile(TempClientFileName,ClientFileName);
END
Let's give a try to this, and let me know if work correctly
Thank you psice and Palle Arentoft for your tips, really appreciated!
I've finally solverd this issue like this:
lShipment.CALCFIELDS(Sticker); lTmpBLob.Blob := lShipment.Sticker; lTempServerFileName := lFileManagement.ServerTempFileName('.pdf'); lFileManagement.BLOBExportToServerFile(lTmpBLob,lTempServerFileName); lFileManagement.DownloadToFile(lTempServerFileName, 'c:\XML\Pegatinas\'+lShipment."No."+'.pdf');
Thank you again!