Ejemplo n.º 1
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value is HttpPostedFileBase)
            {
                HttpPostedFileBase file          = (HttpPostedFileBase)value;
                string             fileName      = file.FileName;
                string             fileExtension = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                int fileSize = file.ContentLength;

                if (AllowedExtensions.Contains(fileExtension))
                {
                    if (fileSize <= ContentLength)
                    {
                        return(ValidationResult.Success);
                    }
                    else
                    {
                        return(new ValidationResult("The Uploaded file must be less than or equal" + ContentLength / 1024 / 1024 + "MB."));
                    }
                }
                else
                {
                    return(new ValidationResult("The Uploaded file must be of one these extensions (" + AllowedExtensions.ToString() + ")."));
                }
            }
            else
            {
                return(new ValidationResult("You Should Upload File."));
            }
        }