Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Request for the permission of type 'FileIOPermission' failed

Posted on by 305

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Request for the permission of type 'FileIOPermission' failed

    Hi Prabakaran,

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

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Request for the permission of type 'FileIOPermission' failed

    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');

  • Suggested answer
    Rudi Hansen Profile Picture
    Rudi Hansen 3,987 on at
    RE: Request for the permission of type 'FileIOPermission' failed

    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.

  • Prabakaran.R Profile Picture
    Prabakaran.R 305 on at
    RE: Request for the permission of type 'FileIOPermission' failed

    Hi Mehdi,

    Thank you for reply, I have used that.

    Thank you

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Request for the permission of type 'FileIOPermission' failed

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

  • Prabakaran.R Profile Picture
    Prabakaran.R 305 on at
    RE: Request for the permission of type 'FileIOPermission' failed

    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
    Community Member Microsoft Employee on at
    RE: Request for the permission of type 'FileIOPermission' failed

    Hi Prabakaran,

    Coul you please send me your code ?

    Thanks

  • Prabakaran.R Profile Picture
    Prabakaran.R 305 on at
    RE: Request for the permission of type 'FileIOPermission' failed

    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

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Request for the permission of type 'FileIOPermission' failed

    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans