【发布时间】:2019-11-29 15:03:53
【问题描述】:
我有以下抛出异常: System.ArgumentException: '空文件名不合法。 参数名称:sourceFileName'
public bool ArchiveFile()
{
int fileCount = Directory.GetFiles(@"\\company\Archive\IN\InvoiceTest\Inbox\").Length;
DirectoryInfo diFileCheck = new DirectoryInfo(@"\\company\Archive\IN\InvoiceTest\Inbox\");
foreach (var fi in diFileCheck.GetFiles())
{
string strSourceFile = Path.GetFileName(@"\\company\Archive\\IN\InvoiceTest\Inbox\");
string strDestination =Path.Combine(@"\\company\ArchiveIN\InvoiceTest\Archive\", strSourceFile);
File.Move(strSourceFile, strDestination);
}
if (fileCount==0)
{
string strMessage = "No file found in directory: \n\n";
MessageBox.Show(strMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
else
{
return true;
}
}
【问题讨论】:
-
如果没有文件名,您期望会发生什么?如果有人回答“Wich file?”这个问题,你会发生什么合乎逻辑的事情?沉默?
-
在哪里定义文件名?