Reputation: 101
I trying to copy a file from a temporary directory to a folder which a user chooses. I am using C#, and the folder that I'm using is empty.
The code i'm using is:
File.Copy(srcPath, landscapebox.Text, true);
srcPath
is a temporary folder
landscapebox
is a text box which will have a directory inputted into it. It should look like:
"C:\Users\####\Folder\Folder"
But instead I get:
An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
Additional information: The target file "C:\Users\###\Desktop\####\TestFolder" is a directory, not a file.
Help! I don't know what I'm doing wrong!
Upvotes: 0
Views: 484
Reputation: 35260
That's because the second argument in File.Copy is the destination file path not the destination folder path.
You can construct the destination file name from your input folder like this:
File.Copy(srcPath,
Path.Combine(landscapebox.Text, Path.GetFileName(srcPath)), true);
Upvotes: 6