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 14
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;
            }
  • gdrenteria Profile Picture
    gdrenteria 14,573 Most Valuable Professional on at
    File Management
  • JJMc Profile Picture
    JJMc 291 on at
    File Management
    If OnPrem, you can pass the stream to a BLOB and then Tablexxx.BlobField.Export(PathAndFileName.Ext);
     
    Kind regards
  • RO-22071332-0 Profile Picture
    RO-22071332-0 14 on at
    File Management
    Hello, 
    Thanks for the case of cloud. This deployment is on premise - What actions are available for on premise deployment? 
  • YUN ZHU Profile Picture
    YUN ZHU 78,034 Super User 2025 Season 1 on at
    File Management
    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
     

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,432 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans