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)

Getting error Access to the path is denied

(0) ShareShare
ReportReport
Posted on by 325

Hi Everyone,

I am generating report through X++ and saving it as pdf and emailing as attachment. This has to be done for all employees. 

When I run the class it is working fine, but when I run the class through batch I am getting the error 

Access to the path is denied when the code is generating the report for the second time on wards. 

I have given all Read/write permission to Everyone and I have even given permission in Report server to AOS service and report server accounts. Below is my code

filepath = @"C:\Email\VendorAgingReport.pdf";

queryContracts = contract.parmQueryContracts();

mapEnum = queryContracts.getEnumerator();

printerSettings = ssrsController.parmReportContract().parmPrintSettings();

printerSettings.printMediumType(SRSPrintMediumType::File);
printerSettings.fileFormat(SRSReportFileFormat::PDF);
permissionSet = new Set(Types::Class);
permissionSet.add(new InteropPermission(InteropKind::ClrInterop));
permissionSet.add(new FileIOPermission(filepath, 'rw'));
CodeAccessPermission::assertMultiple(permissionSet);

error trigger point
printerSettings.fileName(filepath));

*This post is locked for comments

I have the same question (0)
  • Ravikumar Profile Picture
    325 on at

    Hi Crispin, thanks for your quick reply.

    I am giving the network path in the below format. Is it fine?

    filepath = @"\\bg9ws07\c:\Email"

  • Ravikumar Profile Picture
    325 on at

    Hi Crispin, 

    I am getting the same error even after trying, prefixing with local host and ip address. As you can see the process working in the first loop but failing from second loop.

    5584.Untitled.png

  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    Please give a try with the below syntax(i.e UNC path).

    either

    @"C$\Email\VendorAgingReport.pdf"  (or) @"\\bg9ws07\\c$\\Email"

  • Ravikumar Profile Picture
    325 on at

    I tried both of your suggestion but still getting the same error. I dont understand why it is failing from Second loop.

    I have given the path other than C and I have gave the rights to service accounts but no luck.

  • Verified answer
    Jonathan  Halland Profile Picture
    11,310 on at

    Hi Ravi.

    I would suggest that you save the File with a different name each time as sometimes there are file locks and AX struggles to overwrite the file just generated

  • Ravikumar Profile Picture
    325 on at

    Hi Jonathan,  thank you. Your suggestion worked for me.

    thanks Crispin and Chaithanya for your help

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
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans