How to delete a folder which has files?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

Here is the C# code

<code
string d = Server.MapPath("/"+Request.ApplicationPath+"/folder/")

if(System.IO.Directory.Exists(d)

System.IO.Directory.Delete(d)

</code

This code works fine if there is no file under folder d. How can I remove the whole folder and all files under it

Thanks
 
Hi Tom,

Change Directory.Delete(d) to Directory.Delete(d, true)

Happy coding!
Morten Wennevik [C# MVP]
 
Back
Top