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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans