Browse a "network" folder and import files (pictures) - NAV 2016

Hi
First - i'm not all that familiar with the 3-tier yet and therefor I struggle a little on different development issues.
One thing i'm working on (and struggeling with) at the moment is how to do the following

We have a lot of items (fashion clothes) and needs to attach pictures in NAV to these. In the old NAV (2-tier) I used the Filerec table to browse a folder - filtered on only files with certain characteristics (.jpg and with a special naming so I knew which item to import to). If I found any files I would import them one by one to the correct Item.

How to browse a folder on either the network or locally on the client?

Hope to hear from you.

Regards
Mads Morre

Best Answer

  • madsmorre
    Answer ✓
    Slawek - your the man!

    I succeded in reading the files in the folder on my client side by using your code and coding tips !!

    I'm now working on importing them and then move the file to a "processed" folder, but I will try and figure this out.

    Thanks a lot for your input. I'm sure taht i will get more familiar with the 3-tier solution by working with it.

    Best Regards
    Mads Morre

Answers

  • This is one of possible ways of addressing your problem:
    SysObj :=  SysDir.GetFiles(FolderPath);
    SysList := SysList.List;
    SysList.AddRange(SysObj);
    
    FOR i := 1 TO SysList.Count DO BEGIN
       CurrentFile := FORMAT(SysList.Item(i-1)); 
       //rest of your code
    END
    
    The variables are

    SysObj : System.Object.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    SysDir : System.IO.Directory.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    SysList : System.Collections.Generic.List`1.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'


    Slawek
    Slawek Guzek - www.yitron.co.uk
    Business Central, MS SQL Server, Wherescape RED;
  • Hi Slawek

    I'm not able to create/find the specified Globals.

    I can create them as DotNet but I can't find the exact Variables your are specifying.

    Regards
    Mads Morre
  • All three are DotNet variables. You should be able to define var name, then type (DotNet), and then paste the subtype from what I've posted.

    If you want to find and define them 'from scratch' please use the assembly : mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

    Slawek
    Slawek Guzek - www.yitron.co.uk
    Business Central, MS SQL Server, Wherescape RED;
  • o2fj6bslf5dc.png

    1ul6f5pnm0jt.png
    Slawek
    Slawek Guzek - www.yitron.co.uk
    Business Central, MS SQL Server, Wherescape RED;
  • I can create my variables now. :)

    What kind of variabel is CurrentFile? Is that the actual file - if I need to do something with it (import it to an item).

    Mads Morre
  • CurrentFile is text, on each loop turn it will hold a full path to a file found in the FolderPath location
    Slawek Guzek - www.yitron.co.uk
    Business Central, MS SQL Server, Wherescape RED;
  • Hi

    I managed to get the code working, but the folder I specify, seems to be from the Serverside. If I ex. Writes 'C:\temp\' it looks at the server - not on my client.

    It is a little more complicated because we haven't got any real network folders - we operate totally in Office365.

    I think that I have found the network path (UNC-path) to my Office365 - but if this isn't useable, we can copy the files to a folder on my local machine and import from there.
    If the UNC-path to Office365 should be useable, it should def. seeing from (my) client side.

    It is prob. me who doesn't understand fully the 3-tier solution.

    /Mads Morre
  • This is how the NAV work these days :). The code is executed by the NST on the server and everyting is seen from the NST point of view. NAV RTC client is just an UI frontend, it does not do any real work.

    If you want to browse the folders on client side (as visible from user PC) you can try to edit the properties on all three DotNET variables and mark them as RunOnClient = Yes
    u446u7w28ehk.png

    You will also have to add a line of code uploading the file to the server before processiing it:
    FOR i := 1 TO SysList.Count DO BEGIN
       CurrentClientFile := FORMAT(SysList.Item(i-1)); 
       ServerFileName := C419.UploadFileSilent(CurrentClientFile);
      // rest of your code processing the ServerFileName 
      // and deleting the ServerFileName afterwards
    END
    

    (C419 is a variable of type codeunit 419)

    Slawek
    Slawek Guzek - www.yitron.co.uk
    Business Central, MS SQL Server, Wherescape RED;
  • madsmorre
    Answer ✓
    Slawek - your the man!

    I succeded in reading the files in the folder on my client side by using your code and coding tips !!

    I'm now working on importing them and then move the file to a "processed" folder, but I will try and figure this out.

    Thanks a lot for your input. I'm sure taht i will get more familiar with the 3-tier solution by working with it.

    Best Regards
    Mads Morre
  • If you are interested I made a function to browse folder contents. It indexes thousand of files in seconds. I use it to get modified dates and so, when doing incremental updates.
    Maybe you can use it.
    https://juhl.blog/2017/07/05/get-filelist-using-net/
    Follow me on my blog juhl.blog
  • Thank you, Juhl

    This looks interesting. I will use the Temp-table solution to present the data to the users before importing the pictures to the items.
  • I Know this Post is already pretty old, but you guys should have a look at Codeunit 419. - It's specificly made to help you handle File Exchange between Server and Client.
  • Hello,

    I want to execute code in the worker thread of Dynamics nav , so the RunOnClient property should be set to "No." Is there another method with the RunOnClient property set to "No"?

    Best regards,