If you want to know the format of an image, you can load the file with the Image class, and check its RawFormat property:
using(Image img = Image.FromFile(@"C:\path\to\img.jpg"))
{
if (img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg))
{
// ...
}
}