I have created a button. In the event handler for the button I want to delete all the files in the folder (abc).
Here is the code for this:
private void button1_Click_1(object sender, EventArgs e)
{
MessageBox.Show("Are you sure!!!! The files in the folder will be deleted permanently");
this.Close();
string[] filePaths = Directory.GetFiles(@"C:\abc\");
foreach (string filePath in filePaths)
File.Delete(filePath);
}
For example, there is a Word file in the folder and if it is opened I get a error message:
The process cannot access the file 'C:\abc\New Microsoft Word Document.docx' because it is being used by another process.