In this article, you will learn what are InStream and OutStream data types. How not to get confused by the naming and how to use them with some examples.

  • What Are InStream And OutStream?
  • The In And Out Confusing Directions
  • InStream Example
  • OutStream Example

What Are InStream And OutStream?

InStream and OutStream are data types that enable reading or writing to BLOB fields and files.

The information can travel thanks to these data types. We can think of them as connections. They connect to a data source to extract or insert information. The data source can be a Blob field, this is where the information is stored.

BLOBs rely heavily on these connections. If we want to master Blob handling we must learn about InStreams and OutStreams.

The In And Out Confusing Directions

The naming of InStream and OutStream can be confusing. If we try to think about ‘In’ as data coming into and ‘Out’ as data coming out of a Blob field we would be wrong.

The InStream data type allows reading information. Every time we want to read something we can think about InStreams.

On the other hand, OutStream allows writing to. When we need to modify a Blob field we will always use OutStream.

You can forget about the directions in and out, and relate InStream to reading and OutStream to writing.

InStream Example

One of the easiest way to use an InStream can be by reading a text from a local file.

First, uploading into the stream with the ‘UploadIntoStream‘ function. Then, reading the information from the stream. As you can see, the connection allows reading the information from a data source, which is the local file:

You can see another example of using InStream for uploading and downloading Media types in the following article:

You can get more information about InStream in the Microsoft documentation.

OutStream Example

Usually, when we use OutStream for writing is because we will read the information at some point. For that reason, Outstream usually works together with InStream.

The following picture shows a simple example of how they can work together. We will use the ‘Temp Blob’ codeunit to store the information about a specific report.

First, we create the connection with ‘TempBlob.CreateOutStream‘. Now, the information is able to travel into the Blob. With ‘Report.SaveAs’ the information is stored in the Blob. Note that the OutStream is passed as a parameter.

After that, we are reading from the Blob with InStream.

In this video example you can see the Xml report generated:

The CopyStream function can be used to copy the content from an InStream into an OutStream.

In this example, we will modify the picture in ‘Company Information’. We are using an Instream to read from the local file. Then, with OutStream we create the connection to the picture field that we wish to modify or write into.

Finally, the information can travel from InStream to OutStream with CopyStream.

Video example:

Get more information about OutStream at the following link.

Get more info about CopyStream in the Microsoft documentation below:

Source code:

codeunit 50010 "InStreamOutStreamMgmt"
    procedure InStrExample()
        InStr: InStream;
        Description: Text;
        Text2: Text;
        UploadIntoStream('', '', '', Description, InStr);

    procedure ShowTop10CustomersInXml()
        TempBlob: codeunit "Temp Blob";
        InStr: InStream;
        OutStr: OutStream;
        Content: Text;
        OutStr := TempBlob.CreateOutStream();
        Report.SaveAs(Report::"Customer - Top 10 List", '', ReportFormat::Xml, OutStr);
        InStr := TempBlob.CreateInStream();

    procedure UploadPictureToCompanyInfo()
        CompanyInformation: Record "Company Information";
        InStr: InStream;
        OutStr: OutStream;
        ImageName: Text;
        if UploadIntoStream('', '', '', ImageName, InStr) then begin
            CopyStream(OutStr, InStr);

That´s all. Hope you find it helpful.

Master InStream And OutStream In Business Central

Post navigation

2 thoughts on “Master InStream And OutStream In Business Central

Leave a Reply

Your email address will not be published. Required fields are marked *