Skip to content

Instantly share code, notes, and snippets.


islaytitans/CustomValidator.cs Secret

Created Jul 12, 2015
What would you like to do?
namespace ISlayTitans.Cms.WebForms.Validators
public class CustomValidator : FormCustomValidator
protected override bool EvaluateIsValid()
bool isValid = false;
if (!String.IsNullOrEmpty(base.ControlToValidate))
Control control = this.FindControl(base.ControlToValidate);
var fileUpload = control as FileUpload;
if (fileUpload != null && fileUpload.HasFile)
isValid = ValidateFile(fileUpload.PostedFile);
return isValid;
// Custom function which calls the various stages of validation
private bool ValidateFile(HttpPostedFile fileUploaded)
bool validMime = ValidateMimeType(fileUploaded);
if (!validMime) return false;
bool validSize = ValidateFileSize(fileUploaded);
if (!validSize) return false;
bool validUpload = ValidateRepeatUpload(fileUploaded);
if (!validUpload) return false;
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment