【发布时间】:2013-02-04 12:02:42
【问题描述】:
我尝试了在this thread 上找到的内容,但没有完全按照我想要的方式工作...我有一个名为photos 的文件夹may 有图片或没有。 picture's name 是客户端的matriculation。我需要将matriculation 作为parameter 传递,并检查是否有picture 名称为matriculation 我传递为parameter
我试过这个:
public void VerifyPhoto(string matriculation)
{
string path = Txt_PhotosPath.Text;
var file = Directory.GetFiles(path, matriculation + ".jpg");
}
我如何检查它是否找到了图片?我试图比较这个 file != null 但它不适用于 var 类型。任何提示? debuging我看到它找到了图片因为有一个String[1]但我不知道check它...
---更新--- path:C:"\Users\admin\Desktop\photos" matriculation:"607659.jpg"
有一个具有该名称的文件,但它一直返回 false 怎么了?
string path = Txt_PhotosPath.Text;
string filename = string.Format("{0}.jpg", matriculation);
if (Directory.Exists(path))
{
if (File.Exists(Path.Combine(path, filename)))
{
return true;
}
else
return false;
}
else
return false;
【问题讨论】:
标签: c# winforms visual-studio-2010