Valentein
Valentein

Reputation: 869

UnauthorizedAccess Exception with File.Copy on a ReadOnly file

Simple question really...

How can I copy a ReadOnly file?

When running a debug build of my very simple Windows Forms app, I'm getting the UnauthoriazedAccess Exception when trying to copy a read-only file from one directory to another:

FileInfo newFile = new FileInfo(fileName);
File.Copy(newFile.FullName, Path.Combine(destinationDirPath, newFile.Name), true);

What do I need to do to get around it? I'm thinking that there's some kind of security or application permission that I need to set for this project...

Upvotes: 1

Views: 1842

Answers (1)

JaredPar
JaredPar

Reputation: 755269

Is it possible that you're getting the exception not for reading the file but for the place you are writing the file? If that's the case you need to make sure you're writing the file to a directory for which the application credentials have access.

Upvotes: 1

Related Questions