File.ViewFromStream in AL: Display Text Directly from Stream

Microsoft Dynamics 365 Business Central 2025 Wave 1 continues to improve its developer experience with handy new features. One of the exciting additions in this release is the File.ViewFromStream method — a simple yet powerful function that enhances how developers interact with files stored in memory.

In the current versions of Business Central, when you need to view an attached document, a report output, or an incoming file, the typical process involves downloading the file first and then opening it with an external application. This can be time-consuming, especially when dealing with multiple files or when you simply need a quick glance at the content. Switching between applications disrupts your workflow and can feel inefficient.

📘 What is File.ViewFromStream?

The new method File.ViewFromStream(Stream: InStream,Text[,Boolean]) enables developers to open or preview a file directly from a stream, without having to save it to a temporary physical file.

This is a major convenience when working with files generated on the fly — such as PDFs, Excel files, or text reports — especially in scenarios where users just need to view or download the file rather than save it on the server.

Syntax

[Ok := ]  File.ViewFromStream(InStream: InStream, FileName: Text [, AllowDownloadAndPrint: Boolean])

🛠 Example:

procedure ShowGeneratedReport()
var
    TempBlob: Codeunit "Temp Blob";
    OutStream: OutStream;
    InStream: InStream;
    ReportContent: Text;
begin
    ReportContent := 'Hello from AL!' + Format(CurrentDateTime) + 'nThis is a preview of your text report.';

    TempBlob.CreateOutStream(OutStream);
    OutStream.WriteText(ReportContent);

    TempBlob.CreateInStream(InStream);
    File.ViewFromStream(InStream, 'ReportPreview.txt', true);
end;

💼 Use Cases

Here are some scenarios where ViewFromStream can be a game-changer:

  • Previewing customer invoices or sales reports generated on-demand.
  • Opening files attached in workflow approvals.
  • On-the-fly document generation in extensions or apps.

The File.ViewFromStream method offers a powerful and user-friendly way to present stream content directly within Dynamics 365 Business Central. The File.ViewFromStream method is a lightweight, client-friendly way to present text content on the fly in Business Central.

Stay tuned for more.

Original Post https://ammolhsaallvi.blog/2025/04/15/file-viewfromstream-in-al-display-text-directly-from-stream/

0 Votes: 0 Upvotes, 0 Downvotes (0 Points)

Leave a reply

Join Us
  • X Network2.1K
  • LinkedIn3.8k
  • Bluesky0.5K
Support The Site
Events
April 2025
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30     
« Mar   May »
Follow
Sign In/Sign Up Sidebar Search
Popular Now
Loading

Signing-in 3 seconds...

Signing-up 3 seconds...