Skip to main content

Notifications

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

  • Ravikumar Profile Picture
    325 on at
    RE: Getting error Access to the path is denied

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

    thanks Crispin and Chaithanya for your help

  • Verified answer
    Jonathan  Halland Profile Picture
    11,308 on at
    RE: Getting error Access to the path is denied

    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
    RE: Getting error Access to the path is denied

    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.

  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at
    RE: Getting error Access to the path is denied

    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
    RE: Getting error Access to the path is denied

    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

  • Ravikumar Profile Picture
    325 on at
    RE: Getting error Access to the path is denied

    Hi Crispin, thanks for your quick reply.

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

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

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics AX (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 100 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 48

#3
Zain Mehmood Profile Picture

Zain Mehmood 6 Moderator

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans