Insert pdf file using Microsoft.Dynamics.BusinessConnectorNet

I need to insert a pdf file into an Ax database using Microsoft.Dynamics.BusinessConnectorNet.dll via a C # application.

I am referring to this article .

Column type AX - Container.

When I insert a binary array the ArgumentException says:

The method arguments provided are not valid.

What should be the data type to insert a file into the AX database?


source to share

2 answers

I think you need to use a class AxaptaContainer

to pass values ​​in a container.

AxaptaRecord axRecord;

    // Login to Microsoft Dynamics AX.
    ax = new Axapta();
    ax.Logon(null, null, null, null);

    // Create a new AddressState table record.
    using (axRecord = ax.CreateAxaptaRecord("TableName"))
        // Provide container for record field.
        AxaptaContainer axContainer = ax.CreateAxaptaContainer();
        axContainer.Add("Some Data");

        axRecord.set_Field("ContainerField", axContainer);

        // Other fields

        // Commit the record to the database.
catch (Exception e)
    Console.WriteLine("Error encountered: {0}", e.Message);
    // Take other error action as needed.


I have not tested it, so please provide some feedback so we can improve the solution.



        Axapta DynAx = new Axapta();
        AxaptaRecord DynRec;
        string strUserName = "";
        System.Net.NetworkCredential nc = new System.Net.NetworkCredential("", "");

        string tableName = "";

        DynAx.LogonAs(strUserName.Trim(), "", nc, dataAreaId, "en-us","", "");

            using (DynRec = DynAx.CreateAxaptaRecord(tableName))
                var binData = DynAx.CreateAxaptaObject("Bindata");
                var loaded = binData.Call("loadFile", path);
                var data = binData.Call("getData");

                AxaptaContainer axc = DynAx.CreateAxaptaContainer();


                DynRec.set_Field("ATTACHMENT", axc.get_Item(1));

                // Commit the record to the database.
        catch (Exception ex)
            return false;


Authenticate to Ax, get a container from the Ax Bindata class and save the entry.



All Articles