c# - 为什么 System.IO.File 在文件确实存在时返回 false?

标签 c#

我正在使用 System.IO.File.Exists 检查文件是否存在。但是,对于我知道存在的文件,它返回 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")));

关于c# - 为什么 System.IO.File 在文件确实存在时返回 false?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10770878/

相关文章:

c# - 使用 NAudio 播放带有自定义编解码器的 WAV

c# - 在 C# 中,public、private、protected 和没有访问修饰符有什么区别?

c# - 非常频繁地更新datagridview

c# - 使用 MongoDatabase 类而不是 MongoDatabaseImpl

c# - Xamarin android数据保存到json文件

c# - 阻止函数并等待事件 C#

c# - 是否可以在 'RightToLeft' 属性设置为 'Yes' 的组合框中使用左对齐文本?

c# - 跨页播放的音乐播放器

c# - .Net Core 2.0外键默认为0

c# - 重命名 Blazor 组件文件名时出现错误