Delete File

suggest change
string path = @"c:\path\to\file.txt";

While Delete does not throw exception if file doesn’t exist, it will throw exception e.g. if specified path is invalid or 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:

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

Table Of Contents