简体   繁体   中英

How come System.IO.File is returning false when the file does exist?

I'm using System.IO.File.Exists to check if a file exists. However, it's returning false for a file that I know exists. The code is the following:

Assert.IsTrue(System.IO.File.Exists(@"\ImportRepositoryTest\Version2.xml"));

How come System.IO.File is returning false when the file does exist?

尝试

Assert.IsTrue(System.IO.File.Exists(Path.Combine(TestContext.TestDeploymentDir,  @"\ImportRepositoryTest\Version2.xml")));

Change it to Assert.IsTrue(System.IO.File.Exists(@".\\ImportRepositoryTest\\Version2.xml")); (with a ".") and double check to see if you marked your file as "copy always".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM