如何检测项目文件夹中是否存在文件?

VHa*_*ded 3 c# file-exists

我在项目文件夹中有一组图像.

如何检测我的项目文件夹中是否存在图像?我正在使用c#.谢谢.

Wou*_*ens 11

if (System.IO.File.Exists("pathtofile"))
  //it exist
else
  //it does not exist
Run Code Online (Sandbox Code Playgroud)

在提出问题之后编辑了我的答案:

我复制了代码并更改了退出功能,这应该可行

string type = Path.GetExtension(filepath); 
string path = @"image/" + type + ".png"; 
//if(System.IO.File.Exists(path)) I forgot to use the full path
if (System.IO.File.Exists(Path.Combine(Directory.GetCurrentDirectory(), path)))
 { return path; } 
else 
 { return @"image/other.png"; }
Run Code Online (Sandbox Code Playgroud)

在部署应用程序时,这确实有效