-
-
Save LSTANCZYK/8853d01700b159c05449ba9c273875d5 to your computer and use it in GitHub Desktop.
C# class to check image file type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.ComponentModel.DataAnnotations; | |
using System.Text.RegularExpressions; | |
namespace MvcMovie.Service.AppService | |
{ | |
public class ImageType : ValidationAttribute | |
{ | |
public override bool IsValid(object value) | |
{ | |
if (value == null) | |
{ | |
return true; | |
} | |
string postedFileName = ((HttpPostedFileBase)value).FileName.ToLower(), | |
pattern = @".*(\.[Jj][Pp][Gg]|\.[Gg][Ii][Ff]|\.[Jj][Pp][Ee][Gg]|\.[Pp][Nn][Gg])"; | |
if ( ! Regex.IsMatch(postedFileName, pattern)) | |
{ | |
return false; | |
} | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment