Microsoft Dynamics 365 Blog

We are calling AX code from Enterprise Portal that uses WinApi::CopyFile method.

When we run EP from a browser window that is running on the same machine as Business Connector and IIS, the code works.
If we run EP from a browser window running on a local machine,

error 52

when the target file is on a network drive and the path is given in the format “\\<computername>\<path>”, and

error 3

when the path is given in the format “<drive>:\<<path>”, where <drive> is mapped as a network drive and both paths point to the same path and file name.

The solution is to use WinAPIServer instead of WinAPI.
From Dynamics AX Writing Secure X++ Code white paper you will find following:

All methods on the WinAPI are restricted to run only on the client. A new class, WinAPIServer, has been created. This class has a limited subset of the WinAPI functionality. Each method call on the WinAPIServer class is authorized before it can call into Windows. It is important to use the right version of the class.
Calls made through WinAPIServer will execute in the security context of the AOS. Typically, the authenticated user running the client will not have any privileges on the AOS. This can lead to potential security issues if the AOS performs arbitrary tasks on behalf of the client.

As method DocuActionArchive.add() is not run on server but on client you cannot use WinAPIServer. So solution here is to write method which will be run on server.
If you want to store files from document management on Sharepoint then in “Document management parameters” you should use UNC patch to document library, please see following links for reference: Accessing SharePoint Document Library through UNC Path

We're always looking for feedback and would like to hear from you. Please head to the Dynamics 365 Community to start a discussion, ask questions, and tell us what you think!