I am sharing today a method which can help you get files in a particular path.
static container findMatchingFiles(
str _folderPath
, str _filePattern = '*.jpg*')
{
System.IO.DirectoryInfo directory;
System.IO.FileInfo[] files;
System.IO.FileInfo file;
InteropPermission permission;
container fileTypes;
Counter counter = 1;
str fileName;
counter filesCount;
counter loop;
container mathchingFiles;
;
permission = new InteropPermission(InteropKind::ClrInterop);
permission.assert();
directory = new System.IO.DirectoryInfo(_folderPath);
files = directory.GetFiles(_filePattern);
filesCount = files.get_Length();
fileTypes = ['*.bmp*','*.jpeg*','*.gif*','*.jpg*','*.png*'];
while(filesCount == 0 && counter <= conLen(fileTypes))
{
_filePattern = conPeek(fileTypes,counter);
files = directory.GetFiles(_filePattern);
filesCount = files.get_Length();
counter++;
}
for (loop = 0; loop < filesCount; loop++)
{
file = files.GetValue(loop);
fileName = file.get_FullName();
mathchingFiles = conins(mathchingFiles, conlen(mathchingFiles) + 1, fileName);
}
CodeAccessPermission::revertAssert();
return mathchingFiles;
}
Friday, March 18, 2016
Monday, January 18, 2016
Reading images and displaying on report
To display images on a SSRS report in AX we can use below code.
Sometimes we need to show images on SSRS reports, for that purpose we can use below code to fetch the image from a table field as assign to the TmpTable used in SSRS report.
Replace <Table.Field> with your table name and field name
imagePath = conPeek(PackingSlipReportDP::findMatchingFiles(<Table.Field>,'*.jpg*'),1);
new FileIOPermission(imagePath,'r').assert();
if ( WinAPI::fileExists(imagePath))
{
binData.loadFile(imagePath);
logoContainer = binData.getData();
<Table.Field>= logoContainer;
}
CodeAccessPermission::revertAssert();
Sometimes we need to show images on SSRS reports, for that purpose we can use below code to fetch the image from a table field as assign to the TmpTable used in SSRS report.
Replace <Table.Field> with your table name and field name
imagePath = conPeek(PackingSlipReportDP::findMatchingFiles(<Table.Field>,'*.jpg*'),1);
new FileIOPermission(imagePath,'r').assert();
if ( WinAPI::fileExists(imagePath))
{
binData.loadFile(imagePath);
logoContainer = binData.getData();
<Table.Field>= logoContainer;
}
CodeAccessPermission::revertAssert();
Subscribe to:
Posts (Atom)