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!
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.