Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Version: Available or changed with runtime version 15.0.
Opens a file from server computer on the client computer in preview mode. The client computer is the computer that is running the browser that accesses the web client.
Note
This method is supported only in Business Central on-premises.
Syntax
[Ok := ] File.View(FromFile: Text [, AllowDownloadAndPrint: Boolean])
Note
This method can be invoked without specifying the data type name.
Parameters
FromFile
Type: Text
The name of the file on the server that you want to preview on the client computer.
[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-premises environments, use File.ViewFromStream.
Example
This example shows how to use the File.View
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";
MyOutStream: OutStream;
MyInStream: InStream;
FileName: Text;
Success: Boolean;
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) 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