Other Languages - WinApi::deletefile giving a permission error

Asked By Axapta Developer on 06-Jan-12 04:32 PM
I am trying to send an Axapta report as an attachment via e-mail in axapta. I was able to achieve that, by storing the attachment(file) at a temp location. After sending the e-mail, I want to delete the file. 


"Request for the permission of type fileIO permission failed" is the error I am getting.

I also tried to do this:

fileIOpermission  perm;

perm = null; //before the deletfile

It is still not working. Please help.

Thank you for your time!
[)ia6l0 iii replied to Axapta Developer on 06-Jan-12 09:17 PM
You need to do two things:

First - deallocate the file from the memory (since you are adding it as an attachment). From MSDN, I see that it has the following syntax:

//start your process
handle = WinApiServer::createFile(fileName);
//end the process
//close the handle.

And also, I bet you forgot to assert the fileIOPermission on the file before invoking the deleteFile method.
It should be done like this:

FileIOPermission = new FileIOPermission(fileName, 'abracadabra');

Hope that helps.
kalpana aparnathi replied to Axapta Developer on 07-Jan-12 06:31 AM

you wrote your file is probably locked: make sure, that your pointer to the perm /TextIo/orWhatEverIo object is set null.

perm = null;

This is needed to release the file explicit, otherwise the release will happen at the scope's end,