I’m having some major trouble deleting directories. I’m working building a ADMIN tool to delete directories that my clients create but then ask to delete them. You would think this is simple:
using (var context = Impersonator.LogOn(user, password, domain))
{
try
{
dir = new DirectoryInfo(path);
dir.Delete(true);
}
catch (Exception ex)
{
return string.Format("Error:{0}", ex.Message);
}
finally
{
context.Undo();
}
}
Now no matter what I do I can’t delete the folder. response is alway “Access to the path is denied”. I’ve doubled check the path, the login everything.
Please tell me what I’m doing wrong.
Server: win2008 web edition
ASP.NET: 4
I recently solved this identical problem by first deleting all the files in the folder, then deleting the folder.
To me, the error message about access was misleading.
Sometimes I also encounter this when deleting files in Windows Explorer. Once in a while, it balks at deleting the directory until you delete the files in it. I have never figured out why.
Here’s my code: