I tried what I found on this thread but didnt worked exactly the way I wanted... I have a folder named photos it may has pictures or not. The picture's name is the matriculation of the clients. I need to pass the matriculation as parameter and check if there is a picture with the name of the matriculation I passed as parameter
I tried this:
public void VerifyPhoto(string matriculation)
{
string path = Txt_PhotosPath.Text;
var file = Directory.GetFiles(path, matriculation + ".jpg");
}
How may I check if it found the picture or not ? I tried to compare this, file != null but it does not work with var type. Any tip ? debuging I saw it found the picture because there's a String[1] but I don't know ho to check it...
---Update--- path:C:"\Users\admin\Desktop\photos" matriculation:"607659.jpg"
There is a file with that name but it keeps returning false what's wrong?
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;
if (File.Exists(Path.Combine(path, matriculation + ".jpg"));
Use Path.Combine and Directory+File.Exists:
public bool VerifyPhoto(string matriculation)
{
string dir = Txt_PhotosPath.Text;
if(Directory.Exists(dir))
{
string fileName = string.Format("{0}.jpg", matriculation);
if(File.Exists(Path.Combine(dir, fileName)))
return true;
else
return false;
}
else
return false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With