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;
Here are some scenarios where ViewFromStream
can be a game-changer:
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/