web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

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

File Management

(1) ShareShare
ReportReport
Posted on by 29
Hello,
 
Due to the large number documents in our industry would like to store all attachments to documents e.g. sales invoices to a local shared file system. 
I have managed to do code that can upload and download a file to stream.
What am i unable to achieve is sending that file to a specific folder. Instead, it downloads to the downloads- any suggestions? 
 action(UploadtoLocalDisk)
            {
                ApplicationArea = All;
                Caption = 'Upload to Local Disk';
                trigger OnAction()
                var
                    InStream: InStream;
                    FileName: Text;
                    FilePath: Text;
                    RecRef: RecordRef;
                    LocalFileAttachment: Record "Local File Attachment";
                    TempBlob: Codeunit "Temp Blob";
                    OutStream: OutStream;
                    FileManagement: Codeunit "File Management";
                    FromFilter: Text;
                    NameofFile: Text;
                begin
                    //specifies the types of files that can be uploaded. The pattern 'All Files (*.*)|*.*' allows all file types.
                    FromFilter := 'All Files (*.*)|*.*';
                    //opens dialogue if upload is sucessful, returns a file available instream
                    if UploadIntoStream('Select a file', '', FromFilter, FileName, InStream) then begin
                        //store file name
                        NameofFile := FileName + Format(CreateGUID()) + NameofFile + '.pdf';
                        FilePath := 'D:\Bcdocs';
                        TempBlob.CreateOutStream(OutStream);
                        CopyStream(OutStream, InStream);
                        //  FileManagement.BLOBExport(TempBlob, NameofFile, true);
                        DownloadFromStream(InStream, '', FilePath, '', NameofFile);
 
                        RecRef.GetTable(Rec);
                        LocalFileAttachment.Init();
                        LocalFileAttachment."File Path" := FilePath;
                        LocalFileAttachment."Record ID" := RecRef.RecordId();
                        LocalFileAttachment.Insert();
                    end;
                end;
            }
I have the same question (0)
  • YUN ZHU Profile Picture
    101,995 Super User 2026 Season 1 on at
    If it is the cloud version, this cannot be done because the cloud server cannot find your local folder. You can consider other solutions, such as saving files to OneDrive, Sharepoint, or Azure Storage, etc.
     
    Hope this helps.
    Thanks.
    ZHU
     
  • RO-22071332-0 Profile Picture
    29 on at
    Hello, 
    Thanks for the case of cloud. This deployment is on premise - What actions are available for on premise deployment? 
  • JJMc Profile Picture
    293 on at
    If OnPrem, you can pass the stream to a BLOB and then Tablexxx.BlobField.Export(PathAndFileName.Ext);
     
    Kind regards
  • Gerardo Rentería García Profile Picture
    27,054 Most Valuable Professional on at

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,371 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,806 Super User 2026 Season 1

#3
AndrewThomas81 Profile Picture

AndrewThomas81 1,371

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans