Programatically uploading image into document handling

I’ve got 30 gigs of product images that are related to products in our current system, i want to be able to upload the images and attach them to the inventory items via the docuRef programatically,

Can anyone share some insight on how this is done?

Hi Ryan,

Thats a lot of images you have got and automating them straight forward wont be easy.

For starters, how are you going to link which image should be attached to which item. In the below code I’m making the following assumptions,

  1. Image name is equal to the item name
  2. Image is of the jpeg format with an extension .jpg

The following code will automatically upload all images to their respective items,

static void Job1(Args _args)
DocuRef docuRef;
DocuValue docuValue;
InventTable inventTable;

System.String[] fileNames;
int fileCount, i;

str fileName, trimmedFileName;
BinData binData;


binData = new BinData();
fileNames = System.IO.Directory::GetFiles(@“C:\Images”);

fileCount = fileNames.get_Length();

for (i=0; i<fileCount; i++)
fileName = fileNames.GetValue(i);

// Get only the file name. If value returned is C:\Images\Car.jpg, get only Car.jpg
trimmedFileName = substr(fileName, strscan(fileName, ‘\’, strlen(fileName), -strlen(fileName))+ 1, strlen(fileName));

if (trimmedFileName)
// Assuming file extension is always .jpg, removing it
trimmedFileName = strreplace(trimmedFileName, “.jpg”, “”);
// assuming image name matches item name in AX
inventTable = InventTable::find(trimmedFileName);

if (inventTable)
docuValue.File = binData.getData();

docuRef.ValueRecId = docuValue.RecId;
docuRef.RefTableId = tableNum(InventTable);
docuRef.RefRecId = inventTable.RecId;
docuRef.RefCompanyId = curext();
docuRef.TypeId = “Image”;


Hope this helps. Do let me know if you have more specifics and we can work it out further.

Hii Zubir

Thanks For ur post,uploading Employees / Dependents photos. Attachments to be uploaded to the system automatically, as it has to be done on the system directly. can u please guide how to do this

Hi Zubair,

Could we also upload image for inventory location in AX 2012?



It’s also questionable whether you really want to bloat up your AX database by 30 GB. A link to existing storage might be a suitable alternative.