I was wondering how I can set a default path for a Open File
dialog in X++.
The situation is this: In Microsoft Dynamics AX there's the form InventTable
, which shows all data concerning our inventory.
On of the properties of every item is an image. These images are all stored in the same folder on our server. So when we press the button to set or change the image, I would like the dialog box to automatically go to this folder, so users don't have to go there themselves.
This is the code behind the Change Image
-button so far:
void clicked()
{
FilenameFilter filter = ['Image Files','*.bmp;*.jpg;*.gif;*.jpeg'];
BinData binData = new BinData();
str extention, path, nameOfFile;
super();
imageFilePathName = WinAPI::getOpenFileName(element.hWnd(),filter, '', "@SYS53008", '','');
if (imageFilePathname && WinAPI::fileExists(imageFilePathName))
{
[path, nameOfFile, extention] = fileNameSplit(imageFilePathName);
if (extention == '.bmp' ||
extention == '.jpg' ||
extention == '.gif' ||
extention == '.jpeg')
{
binData.loadFile(imageFilePathName);
imageContainer = binData.getData();
inventTableImage.ADUImage = imageFilePathName;
element.saveImage();
element.showLogo();
}
else
{
throw error("@SYS89176");
}
}
}
I've read that I could set a default path in the getOpenFileName
-method, but that doesn't seem to work.
The form itself has a method called filenameLookupInitialPath
which returns just an empty string.
the default path parameter works fine for me in Ax 2012 RTM 3. Are you sure the code is being executed on the correct tier and the path is correct?
WinAPI::getOpenFileName(0, conNull(), @'C:\users\', '');