@volpav's answer will fix your problem, but this great if not the cleanest way to handle this problem.
More elegant would be defining a list of accepted extensions and checking for ext in the list. The advantage of this is that it is easier to maintain if you ever have to change valid types later, and that you can make extensions user-definable if desired.
In the example below, I define a constant (readonly variable) for my class that contains an array with all exceptions, and use the Contains() extension method to check to see if ext exists inside it when checking in UploadFile
public static readonly string[] VALID_EXTENSIONS = new string[4] { ".png", ".jpg", ".gif", ".jpeg" };
By making it static in the code above, I could use this list in the user interface to indicate that it is with the exception of extensions, instead of guessing what is a valid type of image (there are, after all, other types of images than the ones you included).
source share