Importing csv in custTable Ax

I wrote this code for searching all files *.txt in a folder and importing the data in the CustTable of Ax:

public void run()
{
str fileName;
int handle;
str format = @"*.txt";
str filepath=@"\david\mdm12\ax\mail" ;
;

super();

if(WinApi::folderExists(filepath))
{
[handle,fileName] = WinApi::findFirstFile(filepath+format);
while(fileName)
{
perm = new FileIoPermission(filepath+fileName,“R”);
new InteropPermission(InteropKind::ComInterop).assert();

if (perm == null) return;

asciiIo = new AsciiIo(filepath+fileName,“R”);
asciiIo.inFieldDelimiter(";");

if (asciiIo != null)
{
con = asciiIo.read();
while (asciiIo.status() == IO_Status::Ok)
{
accountNum = conPeek(con,1);
email = conPeek(con,2);

select forupdate Email from custTable where custTable.AccountNum == accountNum;
ttsbegin;
Custtable.Email = email;
Custtable.doUpdate();
ttscommit;
con = asciiIo.read();
}
asciiIo = null;
WINAPI::copyFile(filepath+fileName,filepath+@“processati”+fileName);
WINAPI::deleteFile(filepath+fileName);
CodeAccessPermission::revertAssert();
}
filename = WinApi::findNextFile(handle);
}
WinApi::closeHandle(handle);
}
}

When i execute that from a client it work perfect 100%, but when in the properties of the class i set up Run ON Server and i’m trying to execute in a batch job the system give me this error:

missing inizialization of object Asciiio…

and

Request autorization of FileIoPermission failed.

Someone can help me.

Thanks

And what user is used in the batch? Likely the executing user is the AOS service account and it doesn’t have read access to the file, therefore it fails.

You have to either add permissions for AOS service account or run the batch process as a different user.