Edit

Share via


File.ViewFromStream(InStream, Text [, Boolean]) Method

Version: Available or changed with runtime version 15.0.

Opens a file from the server on the client computer in preview mode. The client computer is defined as the machine running the browser accessing the web client.

Syntax

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

Note

This method can be invoked without specifying the data type name.

Parameters

InStream
 Type: InStream
An InStream that you want to use to send the data in a file on the Business Central server to be previewed on the client computer.

FileName
 Type: Text
The name of the file that will be viewed in the client.

[Optional] AllowDownloadAndPrint
 Type: Boolean
Whether to allow the user to download or print the file from the client or not.

Return Value

[Optional] Ok
 Type: Boolean
true if the viewer was opened on the client; otherwise false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.

Remarks

This method works only in Business Central online environments and supports PDF files. For on-premise environments, use File.View.

Example

This example shows how to use the File.ViewFromStream method to preview the Customer - Top 10 List report as a PDF file embedded in the client UI.

procedure ShowTop10CustomersReport()
var
    TempBlob: Codeunit "Temp Blob";
    MyInStream: InStream;
    MyOutStream: OutStream;
    FileName: Text;
    Success: Boolean;
    RecRef: RecordRef; // Declare a RecordRef variable
begin
    // Define the file name for the PDF
    FileName := 'Top10Customers.pdf';

    // Save the "Customer - Top 10 List" report as a PDF in the TempBlob
    TempBlob.CreateOutStream(MyOutStream);
    if not Report.SaveAs(Report::"Customer - Top 10 List", '', ReportFormat::Pdf, MyOutStream, RecRef) then
        Error('Failed to generate the Top 10 Customers report.');

    // Create an InStream from the TempBlob
    TempBlob.CreateInStream(MyInStream);

    // Display the PDF using File.ViewFromStream
    Success := File.ViewFromStream(MyInStream, FileName, true);

    // Handle the case where the PDF could not be displayed
    if not Success then
        Error('Failed to display the Top 10 Customers report.');
end;

Tip

The base application uses this method to view PDF attachments on documents like sales orders, items, and more. Learn more in the Microsoft.Foundation.Attachment reference.

File data type
Getting started with AL
Developing extensions