Monday, June 29, 2020

READ and WRITE file(s), BLOB and ZIP by using INSREAM and OUTSTREAM in Microsoft Dynamics 365 Business Central

Hi Readers, 

Hope you are doing well.

Today we'll talk about File Management in Business Central. 

INSTREAM and OUTSTREAM are used to access binary data (such as File or BLOB) that are stored in Objects. In this blog, we’ll see how to use InStream and OutStream in AL for Business Central.

InStream:

This is used to read bytes from a stream object in binary format, and you can use the Read and ReadText functions to read that format.


OutStream:

This data type can be used to write bytes to a stream object in binary format, and you can use the Write and WriteText functions to write to that format.


Example 1: Here, an Import procedure is created for Item, wherein we are taking InStream and File Management. First, we have to check if an Image exists and if it does, ask for a confirmation whether the existing Item should be replaced or not. If it is confirmed then a selection is made from your system/server and the Picture is Imported into the Item Record with the help of UploadIntoStream and modifying the same, else exit.

Example 2: Here, an Export procedure is created for Item, wherein we are taking OutStream and File Management. First, we have to check if an Image exists and if it does, then exit. Otherwise, take the Image Stream from the Tenant Media table as that has all the Images which are currently in the Environment and download the Image will the help of DownloadFromStream in your system.

Note: Avoid for loop and Index in Tenant GET if you are only working with Rec, since you will be dealing with only one record and hence doesn’t require it to run more than once.


Example 3: Business Central gives you a facility to Export in ZIP format. If you want to an Export of more than one Image rather than Rec, the Dialog/ Confirmation will be shown for each record, to avoid this, you can use ZIPStream which creates a Stream for all OutStreams and then you can export it as a ZIP file with the help of the function AddStreamToZipStream  from File Management Codeunit. The Export procedure remains the same as Example 2.



I hope you liked this blog. Write your suggestions in the comment section. Keep Supporting and following.

You can also email me at jyotsnaoberainav@gmail.com

Also, visit my website JONAV if you need help with any NAV/BC Services!

Thank you! 
 

 

 

 


No comments:

Post a Comment