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

Notifications

Announcements

No record found.

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
    95,331 Super User 2025 Season 2 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
    291 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
    25,169 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans