Skip to main content

Notifications

Announcements

No record found.

Business Central forum

How can I loop through a folder/Directory to read files in a staging table in Business Central Cloud

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi All,

I am faced with a trivial problem. There is a client of mine who is on NAV 2009 R2 Classic and wants to migrate to Business Central -On Cloud. The client's existing system has an EDI interface which reads files from a specific location and imports data in a staging table and moves the file to an Archive Location.

The existing system uses : FILE, File record variable to achieve the result.

But in Business Central-On Cloud this model fails as it doesn't support File Management the traditional way. How can I achieve the same behavior with Business Central-Cloud ?  

  • Armela Kamenica Profile Picture
    Armela Kamenica 215 on at
    RE: How can I loop through a folder/Directory to read files in a staging table in Business Central Cloud

    Thank you.

    I of course need it  for a client running on the cloud.

  • RE: How can I loop through a folder/Directory to read files in a staging table in Business Central Cloud

    Hello,

    In app.json, add this line:

     "target": "OnPrem"

    That should solve it. Of course providing that your solution is OnPrem. For cloud you woudl have to think of other methods.

  • Armela Kamenica Profile Picture
    Armela Kamenica 215 on at
    RE: How can I loop through a folder/Directory to read files in a staging table in Business Central Cloud

    I understand this is an old post, however when using your code as an extension, I get the error message that  

    Type of Method System.IO.Directory can not be use for extension development ? Any ideas ?

    I have them declared as VAR just like your codeunit

    var

          DirectoryHelper: DotNet Directory;

          ArrayHelper: DotNet Array;

  • JJMc Profile Picture
    JJMc 286 on at
    RE: How can I loop through a folder/Directory to read files in a staging table in Business Central Cloud

    I am afraid that you can't do it out-of-the-box.

    You will have to do it with a Control-Addin and JavaScript.

  • Suggested answer
    RE: How can I loop through a folder/Directory to read files in a staging table in Business Central Cloud

    This is a pretty old post so thank you for reactivating it if the question is still there. Maybe it has also been answered since in other posts, but the basics as far as I can see, is to use DotNet Directory and DotNet Array. If you can get hold of codeunit 419 "File Management" you can get more inspiration there. Below it an example to browse through a folder, I have not tried it in real 2-machine setup, and likely there are more elegant ways to do this, but this will hopefuly get you started:

    codeunit 50105 TestStuff

    {

       Subtype = Normal;

       Access = Public;

       trigger OnRun()

       begin

           Arrayhelper := DirectoryHelper.GetFiles('c:\x\');

           ArrayLen := ArrayHelper.GetLength(0);

           for i := 0 to ArrayLen - 1 do begin

               filename := ArrayHelper.GetValue(i);

               Message(FileName);

           end;

       end;

       var

           DirectoryHelper: DotNet Directory;

           ArrayHelper: DotNet Array;

           ArrayLen: Integer;

           FileName: Text;

           i: Integer;

    }

  • Scofield Y Profile Picture
    Scofield Y 5 on at
    RE: How can I loop through a folder/Directory to read files in a staging table in Business Central Cloud

    Hi All,

    Same problem here. Do we have any solution on this question?

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans