CSV file import error

hi ,

i am trying to import data from CSV file to AX using Batch job the code is like

Job


static void Job_ScheduleBatch2(Args _args)

{

ReadCommaFile1 ReadCommaFile1;

BatchHeader batHeader;

BatchInfo batInfo;

RunBaseBatch rbbTask;

str sParmCaption = “RAMU”;

;

rbbTask = new ReadCommaFile1();

rbbTask.getRunBase();

batInfo = rbbTask .batchInfo();

batInfo .parmCaption(sParmCaption);

batInfo .parmGroupId(""); // The “Empty batch group”.

batHeader = BatchHeader ::construct();

batHeader .addTask(rbbTask);

batHeader.save();

info(strFmt("’%1’ batch has been scheduled.", sParmCaption));

}

class

public class ReadCommaFile1 extends RunBaseBatch
{
Table1 table1;
Name sno,sname;
#define.CurrentVersion(1)
#localmacro.CurrentList
sno,
sname
#endmacro

}

public void run()
{

CommaTextIo file;
container line;

#define.filename(@‘C:\Users\ramu\Desktop\ramu.csv’)
#File

file = new CommaTextIo(#filename, #io_read);

if (!file || file.status() != IO_Status::Ok)
{
throw error(“File cannot be opened.”);
}

line = file.read();
while (file.status() == IO_Status::Ok)
{
table1.sno = conPeek(line,1);
table1.sname = conPeek(line,2);
table1.insert();

info(con2Str(line, ’ - '));
line = file.read();

}

}

public container pack()
{
return [#CurrentVersion,#CurrentList];
}

public boolean unpack(container _packedClass)
{
Version version = RunBase::getVersion(_packedClass);
switch (version)
{
case #CurrentVersion:
[version,#CurrentList] = _packedClass;
break;
default:
return false;
}
return true;
}

protected boolean canGoBatchJournal()
{
/* boolean ret;

ret = super();*/

return true;
}

public boolean runsImpersonated()
{
/* boolean ret;

ret = super();*/

return false;
}

I need to insert data daily, suppose every day 9 am this job need to run. but i shows error as follows

Request for the permission of type ‘FileIOPermission’ failed.

(S)\Classes\FileIOPermission\demand
(S)\Classes\CommaTextIo\new
(S)\Classes\ReadCommaFile1\run - line 13
File cannot be opened.

plz provide solution for this in advance thanks
ramu@sunbridgeindia.com

You haven’t assigned necessary code access permissions, namely new FileIoPermission.assert(). Read the referenced documentation for details.

It’s off topic, nevertheless @‘C:\Users\ramu\Desktop\ramu.csv’ returns a string with double backslashes, which doesn’t make much sense. You have to escape backslashes only if you don’t use @ in front of the string.