Search code examples
axaptax++dynamics-ax-2012-r3

How to upload client file to server?


I need to create form to upload file from client side to server in AX 2012 R3 using X++.

Can some one give me link / example regarding this issue?

I try to search and find that I can use class SysFileStoreManager, but still confused how to use it.


Solution

  • You can find example use of SysFileStoreManager using the Cross-reference Tool. I find it a bit bloated.

    You can do this:

    static client container getPackedFileClient(FileName _fileNameClient) 
    {
        BinData binData = new BinData();
        binData.loadFile(_fileNameClient);
        return binData.getData();
    }
    

    This is the SysFileStoreManager.getPackedFileClient method, but without the protected keyword.
    To save the file:

    static server container saveFileToServer(container _packedFile, Filename _filename)
    {
        #File
        BinData b = new BinData();
        b.setData(_packedFile);
        new FileIOPermission(_filename, #IO_WRITE).assert();
        b.saveFile(_filename);
    }
    

    This is SysFileStoreManager.copyFileToClient_Client adapted for general use. You can the call the methods in sequence:

    saveFileToServer(getPackedFileClient(clienFileName), serverFileName);
    

    The file content is transferred from client to server using a container.