MVC File upload unobtrusive validation

The solution contains MVC server side validators that validates a HttpPostedFileBase minimum file size(MinimumFileSizeValidator), maximum file size(MaximumFileSizeValidator) and the file extension respectively(ValidFileTypeValidator).

C# (8.1 MB)
 
 
 
 
 
5 Star
(2)
845 times
Add to favorites
9/12/2016
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • How about upper case file names?
    1 Posts | Last post June 01, 2017
    • This code is great and saved me a lot of time, but I found it would flag PDF as not a valid file of type pdf.
      I changed the IsValid if statement to either:
      if (fileNameParts[fileNameParts.Length - 1].ToUpper() == validFileType.ToUpper())
      Or
      if (string.Compare(fileNameParts[fileNameParts.Length - 1], validFileType, true) == 0)
      and then it works.  Same in the javascript:
              for (var i = 0; i < validFileTypes.length; i++) {
                  if (validFileTypes[i].toUpperCase() === fileType.toUpperCase()) {
                      return true;
                  }
              }