Store and retrive image from Table to file in Ax 2009 & 2012


JohnkrishImageTable has two fields

1. Name

2. Image ( Container and ExtendtedDataType=Bitmap)

Insert Image

static void JohnkrishImageJob(Args _args)
Bindata binData = new BinData();
FilePath _path;
JohnkrishImageTable _ImageStore;

_path = “F:\\JKG\\Johnkrish.jpg”; // file path

// select _ImageStore where _ImageStore.Name==”John”;
_ImageStore.Image = binData.getData();


Retrive Image

static void TableImageToImageFile(Args _args)
bindata bin = new bindata();
str content;
container image;
JohnkrishImageTable jkit;

select jkit where jkit.Name==”John”;
image = jkit.Image;
// Create the base64 encoded string
// Save it to the file system as a tif format
AifUtil::saveBase64ToFile(@”F:\test.tif”, content);



How to add new resource file to AOT and How to use it in Ax

Axapta provides a very handy feature to allow developers to ship their solution with Axapta built-in image files. In Application Object Tree, you can find resources node. Select resources node and right click; select Create from File, specify the file location for the new resource file. After that you can use this resource file in Axapta without specifying an absolute file path in your hard disk.
Then let’s see how to use this kind of files in Axapta.
First, pick up the resource node from AOT;
Then generate a temporary file for this resource file;
Finally specify the temporary file path for controls.
Here comes an example to show how to use a resource file as a background image of  a given form.
        ResourceNode            resourceNode;
FilePath  imagename;
resourceNode = SysResource::getResourceNode(resourcestr(ResourceName));
if (resourceNode)
resourceNode. AOTload();
imagename =  SysResource::saveToTempFile(resourceNode);
throw Error(“No file exists.”);