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 https://msdn.microsoft.com/EN-US/library/aa868997(v=ax.50).aspx .
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?
+3
source to share
2 answers
I think you need to use a class AxaptaContainer
to pass values in a container.
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.
}
I have not tested it, so please provide some feedback so we can improve the solution.
+4
source to share
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();
}
Authenticate to Ax, get a container from the Ax Bindata class and save the entry.
+2
source to share