I have a button in my ASP.NET’s web application, and when it’s pushed, I simply delete the contents of a folder, and copy-paste some new fresh contents from another folder to it. Both folders are children of the root directory of this application, and everyone group has full access to this folder (just for testing purposes). To delete files and folders of the target folder, I use Directory.Delete method and I return the attributes of each file to normal before deleting it which means that no file is read-only or protected when deleted. This works smoothly. But when someone presses that button sequentially (in less than 15 seconds or so), the second time it throws an exception and shows “The directory is not empty). What should I do? I don’t know what the problem is. I think it should be something related to IO of Operating System (in my case, Windows).
I have a button in my ASP.NET’s web application, and when it’s pushed, I
Share
I found the problem. I was trying to delete a read-only folder. Unfortunately, seems that .NET is not smart enough to show a relevant message.
However, always before copying, moving, or deleting any file or folder, set its attribute to normal: