by Brad
24. January 2008 14:02
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);
}
1dfc0b48-a1fc-4060-9f76-31fb44cd630f|0|.0
Tags:
C#