In my database I have a field that is the tracking number, and that field is also an image name ( .jpg
or .tif
). The issue, that I have cases where the guide number has several images and in the images folder you can appear like this:
nro_guia: GUIA00020---->> BASE DE DATOS
GUIA00020__28042017165654.tif -------->>CARPETA DE IMAGENES
How can I do to be able to validate the existence of the image of that guide?
foreach (DataRow row in dtImagenes.Rows)
{
string nom_imagen_db =
row["NroGuia"].ToString().TrimEnd(' ');
var ruta_imagen = Path.Combine(txt_ruta.Text,
nom_imagen_db + ".tif");
var ruta_imagen_2 = Path.Combine(txt_ruta.Text,
nom_imagen_db + ".jpg");
if (pgb_cargando.Value <= cantidad_imagen_db)
{
pgb_cargando.PerformStep();
}
if (!File.Exists(ruta_imagen) &&
!File.Exists(ruta_imagen_2)
{
string f_guia = row["FechaGuia"].ToString();
guias.InsertarGuiasValidadas(nom_imagen_db,
Convert.ToDateTime(f_guia),DateTime.Now, "NO");
}
}
This code works only if the image name is the same as the guide.
I hope you can help me.
Thanks.
You could search for files that match a pattern that starts with the directory name . If any file exists, it has image, for example something along the lines of:
This will find any file that starts with the guide name plus an underscore
_
, but will still find non-image files. You can now specialize it if you are interested in finding only the extensions you mention. Sure is not optimal as it also retrieves the file names and then does not use them.