I have been struggling with this for some time. I cannot access the file after calling the File.Copy method. Here is what I tried:
File.Copy(sourceFile, destinationFile, true);
FileStream fs = File.Open(destinationFile, FileMode.Open);
I get a UnauthorizedAccessException in the second line. It says: access to the path ... is denied. I also tried to offer a suggestion here , but that didn't work.
Any help is appreciated.
EDIT: That's what I found out. If I do this:
File.Copy(sourceFile, destinationFile, true);
FileStream fs = File.Open(destinationFile, FileMode.Open, FileAccess.Read);
It does not throw an exception. The file I'm trying to get is read-only. So, I tried to remove the read-only attribute as follows:
File.Copy(sourceFile, destinationFile, true);
FileInfo fileInfo = new FileInfo(destinationFile);
fileInfo.IsReadOnly = false;
FileStream fs = File.Open(destinationFile, FileMode.Open, FileAccess.ReadWrite);
, . , , , . , . Windows , . , , .