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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top