Benny Sutton is 4 hire - just click here

Validate File is Image

Is this an image file? This is a weak check for jpeg/gif/png file extension - but the file is on your hard disk already it should be OK! see www.regexr.com/4t9nr

           
        public static bool IsImage(this string FileName)
        {
            return Regex.Match(FileName, @".*(\.[Jj][Pp][Gg]|\.[Gg][Ii][Ff]|\.[Jj][Pp][Ee][Gg]|\.[Pp][Nn][Gg])\b").Success;
        }
 
    

Returns true/false - call like this...

         
            if (!httpPostedFile.FileName.GetFileName().IsImage()) throw new Exception("File does not have an image file extension");