Unfortunately the following code will fail if the file in question is ReadOnly:
So I'd always recommend using the following (especially when Visual Studio keeps annoying checking in files that it shouldn't concern itself with!!)
//Check the file actually exists
if (File.Exists(path))
{
//If its readonly set it back to normal
//Need to "AND" it as it can also be archive, hidden etc
if ( (File.GetAttributes(path) & FileAttributes.ReadOnly)
== FileAttributes.ReadOnly)
File.SetAttributes(path, FileAttributes.Normal);
//Delete the file
File.Delete(path);
}