First step was to give the AOS service user rights to the file folder to be written.
As these were multiple files, permission sets were used.
void importFromWorkstation(MPSWorkstation _tWorkstation)
{
int iNumberOfFiles;
FileName sFileName,fileNamePerm, inFile;
InteropPermission interopPerm;
Set permissionSet, permSetFiles;
System.Array files;
int i, j;
container fList;
#File
;
permissionSet = new Set(Types::Class);
permissionSet.add(new InterOpPermission(InteropKind::ClrInterop));
CodeAccessPermission::assertMultiple(permissionSet);
files = System.IO.Directory::GetFiles(_tWorkstation.InDir, "*.ut");
for( i=0; i<ClrInterop::getAnyTypeForObject(files.get_Length()); i++ )
{
fList = conins(fList, conlen(fList)+1, ClrInterop::getAnyTypeForObject(files.GetValue(i)));
}
CodeAccessPermission::revertAssert();
permSetfiles = new Set(Types::Class);
for(j=1;j<=conlen(fList); j++)
{
sFileName = conpeek(fList, j);
//Read files
permSetFiles.add(new FileIOPermission(sFileName, #IO_Read));
//Written files
fileNamePerm = strrem(sFileName, _tWorkstation.InDir) + 'ut';
fileNamePerm = _tWorkstation.MarelOut + 'po'+ fileNamePerm;
permSetFiles.add(new FileIOPermission(fileNamePerm, #io_Write));
fileNamePerm = strrem(sFileName, _tWorkstation.InDir) + 'ut';
fileNamePerm = _tWorkstation.MarelOut + 'dilkur' + fileNamePerm;
permSetFiles.add(new FileIOPermission(fileNamePerm, #io_Write));
}
//Email
permSetFiles.add(new InteropPermission(InteropKind::ComInterop));
// Sys.Io.File.Delete below
permSetFiles.add(new InteropPermission(InteropKind::ClrInterop));
CodeAccessPermission::assertMultiple(permSetFiles);
for(j=1;j<=conlen(fList); j++)
{
sFileName = conpeek(fList, j);
inFile = sFileName;
sFileName = strrem(sFileName, _tWorkstation.InDir) + 'ut';
ttsbegin;
this.parseFileForMarelPO(sFileName, _tWorkstation);
this.parseFile(sFileName, _tWorkstation);
System.IO.File::Delete(inFile);
ttscommit;
}
CodeAccessPermission::revertAssert();
}