web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)
Suggested Answer

Request for the permission of type 'FileIOPermission' failed

(0) ShareShare
ReportReport
Posted on by 313

Hi,

I'm using this code for Export CSV file through batch job but got the FileIOPermission error.

fileName = "\\sssdt-006\\ExportCSV\\" + "ItemDetails" + ".csv";

filepermission = new FileIoPermission(fileName, 'w');
commaIO       = new CommaIO(fileName, 'r');
filepermission.assert();
q       = new Query();
qbds = q.addDataSource(tablenum(InventTable));
qbr   = qbds.addRange(fieldnum(InventTable,ItemId));
qr     = new QueryRun(q);
commaIO.write("ItemId");
while (qr.next())
{
inventTable = qr.get(tablenum(InventTable));
commaIO.write(inventTable.ItemId);
commaIO.write(output);
}
CodeAccessPermission::revertAssert();

4011.Error.png

Thanks for the help in advance.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Prabakaran

    You could see tutorial below : 

    https://community.dynamics.com/ax/b/dynamicsaxinsideout/archive/2015/11/13/x-export-data-from-table-to-a-csv-file

    NB : If it resolve your problem please mark as answered :D

  • Prabakaran.R Profile Picture
    313 on at

    Hi Mehdi

    Thank you for reply your above link is working fine only for normal job and class but unfortunately its not work for batch job, i got same error, please suggest me some other solution to solve this.

    Thank you

  • Community Member Profile Picture
    on at

    Hi Prabakaran,

    Coul you please send me your code ?

    Thanks

  • Prabakaran.R Profile Picture
    313 on at

    Hi Mehdi,

    Thank you for your response

    This my code , this code take from above link,

    Query q;

    QueryBuildDataSource qbds;

    QueryBuildRange qbr;

    QueryRun qr;

    CommaIO commaIO;

    FileName fileName;

    InventTable inventTable;

    ;

    fileName = "C:\\ExportFile\\" + "ItemDetails" + ".csv"; //Destination of the file

    commaIO = new CommaIO(fileName,'W');

    q = new Query();

    qbds = q.addDataSource(tablenum(InventTable));

    qbr = qbds.addRange(fieldnum(InventTable,ItemId)); //Range

    qr = new QueryRun(q);

    commaIO.write("ItemId","Item Type"); //Header of the CSV File

    //Loop to insert values in the csv from the table

    while( qr.next() )

    {

    inventTable = qr.get(tablenum(InventTable));

    commaIO.write(inventTable.ItemId,enum2str(inventTable.ItemType));

    }

    WINAPI::shellExecute(fileName);

    }

    Thank you

  • Community Member Profile Picture
    on at

    Have you put this code in a class that extends RunBaseBatch ?

  • Prabakaran.R Profile Picture
    313 on at

    Hi Mehdi,

    Thank you for reply, I have used that.

    Thank you

  • Suggested answer
    Rudi Hansen Profile Picture
    4,079 on at

    You need to check if the user that your AOS runs under has access to the folder you are trying to write the file too.

  • Suggested answer
    Community Member Profile Picture
    on at

    Please invert the position of your code:

    your code: filepermission = new FileIoPermission(fileName, 'w');

    commaIO       = new CommaIO(fileName, 'r');

    filepermission.assert();

    the correct code:

    filepermission = new FileIoPermission(fileName, 'w');

    filepermission.assert();

    commaIO       = new CommaIO(fileName, 'r');

  • Community Member Profile Picture
    on at

    Hi Prabakaran,

    So check the file permission or folder permission if user has access to it in write mode

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 16

#2
GiacomoRovai Profile Picture

GiacomoRovai 4

#3
Douglas Noel Profile Picture

Douglas Noel 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans