簡體   English   中英

System.IO.IOException

[英]System.IO.IOException

我試圖將文件從臨時目錄復制到用戶選擇的文件夾。 我正在使用C#,並且我使用的文件夾為空。

我正在使用的代碼是:

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.

救命! 我不知道我在做什么錯!

這是因為File.Copy中的第二個參數是目標文件路徑,而不是目標文件夾路徑

您可以像這樣從輸入文件夾構造目標文件名:

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