The Delete() method will fail with UnauthorizedAccessException if any files in the directory tree have the read-only flag. Delete() cannot delete anything with read-only flag even if the user running the application has priviliges to delete these files.
Recursively remove read-only flag for all files and subdirectories to make sure, that Delete() will actually delete everything.
Example:
staticvoid setAttributesNormal(DirectoryInfo dir)
{
// Remove flags from the current directory
dir.Attributes = FileAttributes.Normal;
// Remove flags from all files in the current directory
foreach (FileInfo file in dir.GetFiles())
{
file.Attributes = FileAttributes.Normal;
}
// Do the same for all subdirectories
foreach (DirectoryInfo subDir in dir.GetDirectories())
{
setAttributesNormal(subDir);
}
}