使用 Microsoft.Dynamics.BusinessConnectorNet 插入 pdf 文件

Insert pdf file using Microsoft.Dynamics.BusinessConnectorNet

我需要使用 Microsoft.Dynamics.BusinessConnectorNet.dll 通过 C# 应用程序将 pdf 文件插入 Ax 数据库。

我参考这篇文章https://msdn.microsoft.com/EN-US/library/aa868997(v=ax.50).aspx

AX 列类型是容器。

当我插入二进制数组时 ArgumentException 说:

The supplied method arguments are not valid.

将文件插入 AX 数据库的数据类型应该是什么?

我猜你必须使用 AxaptaContainer class 在容器中传递值。

AxaptaRecord axRecord;

try
{
    // 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.
        axRecord.Insert();
    }
}
catch (Exception e)
{
    Console.WriteLine("Error encountered: {0}", e.Message);
    // Take other error action as needed.
}

我还没有测试过,所以请提供一些反馈,以便我们改进解决方案。

        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","", "");

        try
        {
            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();

                axc.Add(data);


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

                // Commit the record to the database.
                DynRec.Insert();
            }
        }
        catch (Exception ex)
        {
            return false;
        }
        finally
        {
            DynAx.Logoff();
        }

Ax验证,从Ax Bindata获取容器class并保存记录。