Delete File
suggest changestring 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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents