How do I properly open a file for deletion?
See the question and my original answer on StackOverflowSomething like this:
using (FileStream file = new FileStream(path,
FileMode.Open,
FileAccess.ReadWrite,
FileShare.Delete))
{
// you can read the file here and check your stuff
File.Delete(path);
}
PS: note the 'using' keyword. It allows you to have a cleaner code as it takes care of Dispose calls.