2016-11-30 58 views
0

我试图将文件从临时目录复制到用户选择的文件夹中。我正在使用C#,并且我正在使用的文件夹是空的。System.IO.IOException

我使用的代码是:

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

srcPath是一个临时文件夹

landscapebox是这将有输入到一个目录文本框。它应该看起来像:

"C:\Users\####\Folder\Folder" 

而是我得到:

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. 

帮助!我不知道我做错了什么!

回答

5

这是因为在File.Copy第二个参数是目标文件路径不是目的文件夹路径

您可以从您的输入文件夹构建目标文件名是这样的:

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

哦。这很尴尬 – Hyblocker

相关问题