NAV2016 NAS copy / read file from network drive

rsaritzky
Member Posts: 469
Hi all,
This question has been asked before in a variety of flavors, but I haven't found this particular scenario with an answer.
We have a codeunit running in the NAV2016 job queue. The intent is to read a file on a network share, e.g.
\\servername\Scanfolder\sub\sub\thisfile.txt
It then parses that text file and puts some data in the NAV database.
The issue is that the server cannot find/read this file.
The userid that the service tier is running under has full Active Directory permissions to the \\servername\scanfolder. I can log into the server with this same userid and see the directory and open the file.
If I run the codeunit under the NAV client, this code fails:
If I use the File management codeunit functions, it works when running from a NAV client:
However, when running under a NAS session, the above code fails with this error:
Does anyone have working code that runs under a NAS sessions that reads data from a file on a network share? I don't mind having to copy it to a temp file if necessary, but I haven't found the right combination of methods to do this. I have also been told that the "delegation" method is not necessary for NAV2016 (that it applies only to 2009). I've also tried setting the delegation properties mentioned in other threads, but still no luck.
Thanks in advance,
Ron
This question has been asked before in a variety of flavors, but I haven't found this particular scenario with an answer.
We have a codeunit running in the NAV2016 job queue. The intent is to read a file on a network share, e.g.
\\servername\Scanfolder\sub\sub\thisfile.txt
It then parses that text file and puts some data in the NAV database.
The issue is that the server cannot find/read this file.
The userid that the service tier is running under has full Active Directory permissions to the \\servername\scanfolder. I can log into the server with this same userid and see the directory and open the file.
If I run the codeunit under the NAV client, this code fails:
FileName := '\\servername\data$\Scanned Documents\Logs\CD_NAV_Import.txt'; IF ScanFile.OPEN(FileName) THEN BEGIN IF CONFIRM('Was able to open ' + FileName) THEN; ScanFile.CLOSE; END ELSE IF CONFIRM('Could not open file ' + FileName) THEN; <---Fails EXIT;
If I use the File management codeunit functions, it works when running from a NAV client:
IF NOT FileMgt.ClientFileExists(FileName) THEN EXIT; TempFileName := FileMgt.UploadFileSilent(FileName); IF ScanFile.OPEN(TempFileName) THEN ;
However, when running under a NAS session, the above code fails with this error:
Microsoft Dynamics NAV Server attempted to issue a client callback to create a DotNet object: System.IO.File (CodeUnit 419 File Management). Client callbacks are not supported on Microsoft Dynamics NAV Server.
Does anyone have working code that runs under a NAS sessions that reads data from a file on a network share? I don't mind having to copy it to a temp file if necessary, but I haven't found the right combination of methods to do this. I have also been told that the "delegation" method is not necessary for NAV2016 (that it applies only to 2009). I've also tried setting the delegation properties mentioned in other threads, but still no luck.
Thanks in advance,
Ron
Ron
0
Best Answer
-
I tried a few more functions and got this code to work:
FileName := '\\servername\data$\Scanned Documents\Logs\CD_NAV_Import.txt'; IF FileMgt.ServerFileExists(FileName) THEN BEGIN TempFileName := FileMgt.ServerTempFileName(''); FileMgt.CopyServerFile(FileName,TempFileName,TRUE); ScanFile.WRITEMODE(FALSE); ScanFile.TEXTMODE(TRUE); IF NOT ScanFile.OPEN(TempFileName) THEN ...[rest of processing] END;
Ron0
Answers
-
I'm not sure what you mean here...I'm using the functions in CU419 "as is". I have no DotNet variables defined explicitly.Ron0
-
I am trying to use the functions in CU419 "As is" - there are no dialogs or MESSAGE commands in the functions I am trying, but I'm looking for a way to (a) locate a file on a network drive (b) copy it to the server (if necessary), then process it. So far, I cannot find/open a file, even though the service tier userid has permissions to that network resource. I'm looking for actual code samples.
Thanks
RonRon0 -
I tried a few more functions and got this code to work:
FileName := '\\servername\data$\Scanned Documents\Logs\CD_NAV_Import.txt'; IF FileMgt.ServerFileExists(FileName) THEN BEGIN TempFileName := FileMgt.ServerTempFileName(''); FileMgt.CopyServerFile(FileName,TempFileName,TRUE); ScanFile.WRITEMODE(FALSE); ScanFile.TEXTMODE(TRUE); IF NOT ScanFile.OPEN(TempFileName) THEN ...[rest of processing] END;
Ron0
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