I am trying to delete a file, but the following code doesn’t do that. It doesn’t throw an exception, but the file is still there. Is that possible?
try
{
File.Delete(@"C:\File.txt");
}
catch(Exception e)
{
Console.WriteLine(e);
}
If the file can’t be deleted, the exception should print out, but it doesn’t. Should this fail silently (as in the File.Delete method is swallowing any errors)?
File.Deletedoes not throw an exception if the specified file does not exist. [Some previous versions of the MSDN documentation incorrectly stated that it did].