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 Specified Directory In Asp.net

01.30.2012
| 2246 views |
  • submit to reddit
        // Delete all the files in specified directory in asp.net

 private void DeleteAllFilesInMyDirectory(string MyDirectoryPath)
    {
        if (Directory.Exists(HttpContext.Current.Server.MapPath(MyDirectoryPath)))
        {
            string[] filenames = System.IO.Directory.GetFiles(HttpContext.Current.Server.MapPath(MyDirectoryPath));
            foreach (string filename in currntDirectoryFilenames)
            {
                File.Delete(filename);
            }
        }
    }