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
Hi Jonathan, thank you. Your suggestion worked for me.
thanks Crispin and Chaithanya for your help
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
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.
Hi,
Please give a try with the below syntax(i.e UNC path).
either
@"C$\Email\VendorAgingReport.pdf" (or) @"\\bg9ws07\\c$\\Email"
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.
Hi Crispin, thanks for your quick reply.
I am giving the network path in the below format. Is it fine?
filepath = @"\\bg9ws07\c:\Email"
Mohamed Amine Mahmoudi
100
Super User 2025 Season 1
Community Member
48
Zain Mehmood
6
Moderator