DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Delete All The Files In Directory In Asp.net

01.27.2012
| 3776 views |
  • submit to reddit
        // Delete all the files in directory in asp.net


 private void DeleteDirectoryFiles(string path)
    {
        if (Directory.Exists(HttpContext.Current.Server.MapPath(path)))
        {
            string[] files= System.IO.Directory.GetFiles(HttpContext.Current.Server.MapPath(path));
            foreach (string file in files)
            {
                File.Delete(file);
            }
        }
    }