Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Display PDFs from shared folder in BC On-Prem without saving them to the database

(4) ShareShare
ReportReport
Posted on by 9

Hi community,

I'm working with Business Central On-Premise version 25.1 (Platform 25.0.25866.0 + Application 25.1.25873.25900), in a hybrid code environment.

I already have a fully developed embedded PDF viewer (not the lite version), and until now I’ve been loading documents from the database using Document Attachment.

Now I want to change the approach and read PDF files directly from a local shared folder, for example: \\SRV_NAME\FOLDER_NAME , without storing them in the database.

My goal is to:

  1. Read the PDF file from the UNC path.
  2. Load it into a TempBlob.
  3. Display it embedded in Business Central using the viewer I already have.
  4. Delete the TempBlob after viewing.

The Business Central server has access to the shared folder, and the service runs under a user with the necessary permissions.

I don’t yet have the code to read from disk, and I’m not sure how to do it properly in AL (especially in OnPrem extensions). Could someone help me implement this flow step-by-step, with working AL code compatible with OnPrem?

Thanks in advance!

  • Suggested answer
    YUN ZHU Profile Picture
    85,982 Super User 2025 Season 1 on at
    Display PDFs from shared folder in BC On-Prem without saving them to the database
    You can search for previous NAV solutions, which are still available in BC On-Pre version.
    For example,
     
    Thanks.
    ZHU
  • Gerardo Rentería García Profile Picture
    20,949 Most Valuable Professional on at
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    24,507 Super User 2025 Season 1 on at
    Display PDFs from shared folder in BC On-Prem without saving them to the database
     
    try this procedure :
    procedure LoadPDFIntoTempBlob(UNCPath: Text; var TempBlob: Record TempBlob): Boolean
        var
            InStream: InStream;
            FileManagement: Codeunit "File Management";
            TempFile: Text;
        begin
            // Confirm path exists and ends with ".pdf"
            if not FileManagement.ServerFileExists(UNCPath) then begin
                Error('File not found: %1', UNCPath);
            end;
    
            if not StrEndsWith(LowerCase(UNCPath), '.pdf') then
                Error('File must be a PDF: %1', UNCPath);
    
            // Open the file as InStream
            FileManagement.ServerFileToInStream(UNCPath, InStream);
    
            // Prepare TempBlob
            TempBlob.Init();
            TempBlob.Blob.CreateInStream(InStream);
            TempBlob.Insert();
    
            exit(true);
        end;
    Best regards,
    Mohamed Amine MAHMOUDI

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans