How to Delete a File in C#

The Delete method deletes the specified file permanently. The following code snippet deletes the destination file. 

string destinationFile = @"C:\Temp\Data\MaheshTXCopied.txt";

try
{
    File.Delete(destinationFile);
}

catch
(IOException iox)
{
    Console.WriteLine(iox.Message);
}

Up Next
    Ebook Download
    View all
    Learn
    View all