我使用System.IO.File.Exists
來檢查文件是否存在。但是,它對於我知道存在的文件返回false。代碼如下:當文件存在時,System.IO.File如何返回false?
Assert.IsTrue(System.IO.File.Exists(@"\ImportRepositoryTest\Version2.xml"));
爲什麼System.IO.File
是返回false時,該文件確實存在嗎?
我使用System.IO.File.Exists
來檢查文件是否存在。但是,它對於我知道存在的文件返回false。代碼如下:當文件存在時,System.IO.File如何返回false?
Assert.IsTrue(System.IO.File.Exists(@"\ImportRepositoryTest\Version2.xml"));
爲什麼System.IO.File
是返回false時,該文件確實存在嗎?
嘗試
Assert.IsTrue(System.IO.File.Exists(Path.Combine(TestContext.TestDeploymentDir, @"\ImportRepositoryTest\Version2.xml")));
將其更改爲Assert.IsTrue(System.IO.File.Exists(@".\ImportRepositoryTest\Version2.xml"));
(帶「。」),然後仔細檢查是否將文件標記爲「始終複製」。
你的代碼假定當前驅動器是正確的,並且'\ ImportRepositoryTest'存在該驅動器的根目錄。你確定這些假設是真的嗎? –
你確定相對路徑正確嗎? – WojtekT
是的,在該行之前,我做了data = Framework.Import.data.Loadv2(TestContext.TestDeploymentDir + @「\ ImportRepositoryTest \ Version2.xml」);.如果文件不存在,這會產生一個錯誤(我嘗試使用不存在的文件)。 –