How to get correct network folder path when code runs in batch jobs?
I have a class which runs in batch job to read text files from network folder & imports data in AX 2012 & move file to another folder.
During moving file to destination folder, system is not taking correct path & error log comes as "System.UnauthorizedAccessException: Access to the path is denied."
Source path : \\JCBiztalk\Testing_From\ABC.txt
Destination path : \\JCBiztalk\Testing_To\ABC.txt
when batch job runs & tries to move file, FilePath variable takes path as : \\\\JCBiztalk\\Testing_from\\ABC.txt. (with extra slashes).
I need the same path as Source path & destination path when moving file using System.IO.File::Move(_fromLocation,_toLocation).
I am able to get correct path in directoryInfo using System.IO.DirectoryInfo(_fromLocation), but unable to convert directoryInfo to string to get full path to move file !!
Kindly help me in this.
I don't think that this is the cause of your problem. The extra backslashes are likely just a visualization escaping each backslash (a special character) with another backslash (as the escape character).
Also, the error doesn't say that the folder can't be found, it says that the current user (= AOS service account) doesn't have permissions to work with it. Your test with DirectoryInfo is yet another proof that the path is fine.
Therefore I suggest you look at permissions instead of the path.
Thanks for your reply.
Actually the path (network folder) has Modify permissions for AOS service account. Still error is same.
what other permissions i need to setup ? can you suggest please.
There are quite a few things that may be wrong; unfortunately I don't know how you set up the sharing and things like that.
If I was you, I would first create a simpler test case than going through a batch in AX. For instance, you can change the service account to allow interactive logins, log in as AOS and try to access the file.
I have already tested the same on AX Client. It is working fine. Issue is only when same code runs in batch job.
Could you suggest some alternate code to read & move file on network folders which works in batch jobs?
Testing it on client is useless, because it's a completely different scenario. Proving that your account has permissions and that the file is accessible from the client machine says nothing about permissions of the AOS service account and accessibility from the application server.
I'm not going to give you any alternative code, because that's not where your problem lies. It's about authorization (UnauthorizedAccessException).