To delete all the files from the directory.

Gopesh9
Posted by Gopesh9 under C# category on | Points: 40 | Views : 1605
Suppose you want to delete all the files from the directory then you have to use the following code.

public void deleteFile(string pathDirectory)
{
if (Directory.Exists(HttpContext.Current.Server.MapPath(pathDirectory)))
{
string[] files = System.IO.Directory.GetFiles(HttpContext.Current.Server.MapPath(pathDirectory));
foreach (string name in files)
{
File.Delete(name);
}
}
}

Comments or Responses

Login to post response