File reading

NaviDevNaviDev Member Posts: 365
Hello,

I have this scenario. Wherein the file will be copied thru the network into a map computer directory, and then navision will process the file after detecting it. The question is, is there any function in navision to check if the transfered file is already complete done?
Navision noob....

Answers

  • krikikriki Member, Moderator Posts: 9,110
    No, there isn't. But there are some tricks:

    1) the procedure that moves the file must rename it when it is finished (ex. putting ok at the end of the file). And NAV only reads those files.

    2) Let NAV change the name (ex. putting ok at the end of the file). If the file is locked, the file will NOT be renamed. Then let NAV only read records that are renamed.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • NaviDevNaviDev Member Posts: 365
    Hello Kriki,

    Thanks for your tricks. But I have some difficulties in using those.

    From your :
    1. Transfering of file is done just by "copy and paste" or via FTP. So no other application is connected in transfering the file.

    2. How can I know from nav the the file is Locked? Because I have already use the FILE.OPEN function and actually it can open the file even though the file is still in the process of transfering. :(
    Navision noob....
  • krikikriki Member, Moderator Posts: 9,110
    1. This seems to be difficult.

    2. Use virtual table "File" to find the files in the subdir. Once you find a file, rename it, but do NOT open the file. If it succeeds, it means the file was not locked. After this, you can open the renamed file.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • NaviDevNaviDev Member Posts: 365
    Hello Kriki,

    1. Yeah.

    2. What will I used? the FILE.RENAME? or send a command to the windows Command line?

    Again, thanks for your suggestions.
    Navision noob....
  • damirdamir Member Posts: 28
    Hi,

    you can set write mode to true and then try opening file in the loop. If the file is locked you should get an error. You can make some code like this:

    f.WRITEMODE(true);
    while not f.open(FileName) do
    sleep(1000);

    Best regards,
    Damir
  • krikikriki Member, Moderator Posts: 9,110
    2. you can use file.rename (and save the return-value somewhere to avoid that an ERROR is raised.

    Also the solution of damir can be used. But I do not prefer it because if you only need to read a file, why open it to write? Another reason is that I have done a lot of interfaces and always I found that at the end the file is renamed to make it available (and sometimes another file is created to let see the first file is not locked any more, but this is not a really good way).
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • NaviDevNaviDev Member Posts: 365
    Kriki and Damir,

    Thanks a lot for providing this solutions. I really appreciate it. :thumbsup:
    Navision noob....
Sign In or Register to comment.