简体   繁体   English

System.IO.IOException

[英]System.IO.IOException

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. 我正在使用C#,并且我使用的文件夹为空。

The code i'm using is: 我正在使用的代码是:

File.Copy(srcPath, landscapebox.Text, true);

srcPath is a temporary folder srcPath是一个临时文件夹

landscapebox is a text box which will have a directory inputted into it. landscapebox是一个文本框,其中将输入目录。 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 . 这是因为File.Copy中的第二个参数是目标文件路径,而不是目标文件夹路径

You can construct the destination file name from your input folder like this: 您可以像这样从输入文件夹构造目标文件名:

File.Copy(srcPath, 
    Path.Combine(landscapebox.Text, Path.GetFileName(srcPath)), true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM