Not able to delete a folder / directory


I am not able to delete a folder / directory using System.Io.Directory::Delete(Directory), the folder is NOT EMPTY.

Do you get any error?


Have you tired by deleting the files and then the folder?

Files also not getting deleted, as I am getting error as “File opened in Dynamics Ax.”

What type of files are they? How are you dealing with them before deleting?

From WORD, I converted those files into Password protected PDF files and after my work, I am trying to delete the files (Password protected PDFs).

I am getting the following error:

The process cannot access the file because it is being used by another process

It means that the file was not properly released/closed before deleting.

Try to use FileIOPermission class object, see the documentation and example…/

public server static boolean deleteFile(filename _filename)


FileIOPermission FileIOPerm;


FileIOPerm = new FileIOPermission(_filename,‘w’);




No, it’s not about permissions. The message clearly says that the file can’t be deleted because it’s currently open in an application.