System.IO.FileNotFoundExceptio ... [英] System.IO.FileNotFoundExceptio...
本文介绍了System.IO.FileNotFoundExceptio ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我正在尝试将文件从我的驱动器复制到桌面但是我的代码引发了这个错误:
Hi I am trying to copy a file from my c drive to a desktop but my code raised this error:
引用:
System.IO.FileNotFoundException:找不到文件'C:\ TestTolder \ test.txt'。文件名
System.IO.FileNotFoundException: Could not find file 'C:\TestFolder\test.txt'. File name
public void fnEnvironment()
{
try
{
FileInfo someFile = new FileInfo(@"C:\TestFolder\test.txt");
someFile.CopyTo(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\test.txt");
lblMsg.Text = "Has text.txt has been copied to the Desktop";
}
catch (Exception Ex)
{
lblError.Text = Ex.ToString();
lblError.ForeColor = Color.Red;
}
}
请注意,我有一个名为TestFolder的文件夹,里面有text.txt文件。
有人可以帮助解决这个错误。
}
note that I have a folder called TestFolder and inside I have text.txt file.
Can someone help resolving this error.
推荐答案
我最好的猜测是你有已知文件类型的隐藏文件扩展名在窗户。您的文件可能是.txt.txt
也在你的副本之前..
if(someFile。存在)
{
//复制代码在这里
}
My best guess is you have hide file extensions for known file types on in windows. Your file probably is .txt.txt
also before your copy..
if (someFile.Exists)
{
//copy code here
}
Hi
试试像这样..
1)复制URL并粘贴到Windows搜索中(按Windows键,粘贴在文本框中),看看文件是否出现在那里。
如果文件出现则路径有效,否则检查文件扩展名和目录..
2)把文件放在其他位置尝试,除了C:
Hi Try like this..
1) Copy the URL and paste in the Windows Search ( Press Windows Key , paste in the text box ) and see whether the file appears over there .
if the file appears then the path is valid else check for the file extension and the directory..
2) put the file in some other location and try, other than C:
感谢您的回复,但我已经解决了问题,这是一个权限问题...我已经右键单击该文件夹并检查完全控制来自安全Tab.Thanks无论如何!!
Thanks for your reply but I have resolve the issue,it was a permission issue...I have right click on the folder and check full control from the security Tab.Thanks anyway!!
这篇关于System.IO.FileNotFoundExceptio ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文