Delete File

suggest change
string path = @"c:\path\to\file.txt";
File.Delete(path);

Delete does not throw if the file does not exist. It throws if the path is invalid or the caller does not have the required permissions. You should always wrap calls to Delete inside try-catch block and handle all expected exceptions. In case of possible race conditions, wrap logic inside lock statement.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents