Reputation: 3626
I'm trying to perform a simple File.Move
operation but I get
System.UnauthorizedAccessException exception - Access to the path is denied.
To my knowledge, nothing is using the file I am trying to move (containing folder is closed as well). I can move the file manually via File Explorer just fine. I've tried File.Delete
and it works perfectly fine.
I'm unsure of what is happening - why would File.Move
fail but File.Delete
work if Visual Studio says that access to the path is denied?
Here is my code:
string file = @"C:\Data\VCR\150326\150326.MPG";
string destination = @"G:\ArchiveData\Video";
System.IO.File.Move(file, destination);
Upvotes: 8
Views: 10219
Reputation: 1908
Check your anti virus software. It may be blocking the file move.
Upvotes: 1
Reputation: 3626
So my problem was that my destination path did not include the file name. Adding the filename to my variable destination
makes it work:
string file = @"C:\Data\VCR\150326\150326.MPG";
string destination = @"G:\ArchiveData\Video\150326.MPG";
System.IO.File.Move(file, destination);
Upvotes: 14