0

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!

1 Answer 1

6

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);
Sign up to request clarification or add additional context in comments.

1 Comment

Oh. That's embarrasing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.