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

garychick
Member Posts: 34
Hi ALL,
I have an question about open files in Navision. I have a Codeunit which used to import XMLport.
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?
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?
0
Comments
-
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]0 -
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,0 -
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>'0
-
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 Dev0 -
Hi All,
I have tried something similar to Timo, I receive this problem however:
any ideas on how to solve this?
Hopefully, the Image has came through
0 -
PS
Thanks
0 -
Use File Management codeunit. There are all tools you will need.0
-
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,
David0 -
Check FillFileTable in File Management codeunit.0
-
Sorry, I'm using 2018, I don't have that function.0
-
dvdCasey1997 wrote: »Hi All,
I have tried something similar to Timo, I receive this problem however:
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?0 -
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?
cheers0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions