How to open all files (eg *.xml) in batch in a folder ???

garychickgarychick Member Posts: 34
Hi ALL,

I have an question about open files in Navision. I have a Codeunit which used to import XMLport.
TestFile.OPEN('C:\Output\PO1.xml');
TestFile.CREATEINSTREAM(TestStream);
XMLPORT.IMPORT(50003,TestStream);

Besides PO1.xml, there are also other xml eg PO2.xml, PO3.xml, etc in the Output folder. And what I want to do is to import all *.xml files in the Output folder to Navision, but I don't know exactly how many xml files will be in the folder and the file names of each files. I want to make this codeunit to be able to open and read all the xml file in the Output folder so that I can put this Codeunit in the Job Scheduler and let it run regularly.

Does anyone have some ideas?

Comments

  • Timo_LässerTimo_Lässer Member Posts: 481
    Use the virtual table File.
    Name	DataType	Subtype	Length
    MyFile	Record	File
    
    MyFile.SETRANGE(Path,'C:\Output\');
    MyFile.SETRANGE("Is a file",TRUE);
    if MyFile.FIND('-') THEN
      REPEAT
        TestFile.OPEN(MyFile.Name);
        TestFile.CREATEINSTREAM(TestStream);
        XMLPORT.IMPORT(50003,TestStream);
      UNTIL MyFile.NEXT = 0;
    
    Timo Lässer
    Microsoft Dynamics NAV Developer since 1997
    MSDynamics.de - German Microsoft Dynamics Community - member of [clip]
  • Ravi_ThakkarRavi_Thakkar Member Posts: 392
    Hi Timo,

    Thanks for this post.
    I tried this but I have to refer the shared path for the files.
    Above code try to fetch the files from Local system.

    Any Suggestion ?

    Thanks,
    Ravi_Thakkar
    Ahmedabad, Gujarat, India
    E Mail : [email protected]
  • DenSterDenSter Member Posts: 8,221
    If you have a shared folder mapped to a specific drive letter, use that drive letter instead of C. You can also use the network location. If I remember correctly (it has been YEARS since I've done this) '\\ServerName\<add the rest of the path here>'
  • Wisa123Wisa123 Member Posts: 291
    edited 2016-06-22
    Whenever i do this i usually use .NET
    Array: https://msdn.microsoft.com/en-us/library/system.array(v=vs.110).aspx
    Directory.GetFiles: https://msdn.microsoft.com/en-us/library/system.io.directory.getfiles(v=vs.110).aspx

    Works like a charm, even with UNC paths, only restriction is that the searchPattern parameter does not support RegEx.
    Austrian NAV/BC Dev
  • dvdCasey1997dvdCasey1997 Member Posts: 7
    Hi All,

    I have tried something similar to Timo, I receive this problem however:
    f4bq9vn77yhp.png
    any ideas on how to solve this?

    Hopefully, the Image has came through
  • dvdCasey1997dvdCasey1997 Member Posts: 7
    PS

    Thanks
  • lubostlubost Member Posts: 570
    Use File Management codeunit. There are all tools you will need.
  • dvdCasey1997dvdCasey1997 Member Posts: 7
    Hi lubost,

    Could you possibly elaborate? My issue occurred whenever I tried to open the folder (known after debugging). I should have mentioned this beforehand, apologies.

    Thanks,
    David
  • lubostlubost Member Posts: 570
    Check FillFileTable in File Management codeunit.
  • dvdCasey1997dvdCasey1997 Member Posts: 7
    Sorry, I'm using 2018, I don't have that function.
  • bostjan.les@gmail.com[email protected] Member Posts: 30
    edited 2019-03-04
    Hi All,

    I have tried something similar to Timo, I receive this problem however:
    f4bq9vn77yhp.png
    any ideas on how to solve this?

    Hopefully, the Image has came through

    Does the user under which NAV server is running have write permission to the share where the files are located?
  • Osak3Osak3 Member Posts: 5
    edited 2019-03-18
    Hi,
    You can use the solution that Timo_Lässer gave above.
    Also, check if you can access the folder on NAV server to guarantee that the folder can be accessed from server to server (if this is the case)

    The only issue is you might have to use the shared folder ip adress as server name, eg: \\111.111.111.1\sharefoldername

    then you should check:
    1) Is it run by jobqueue? If so, give jobqueue user acess to the folder
    2) Is it run by user when clicking a btn? If so you need to give folder access or get a way to run the jobqueue entry when the User press the btn.

    Did this help you a bit more?
    cheers
Sign In or Register to comment.