I have am AsyncFileUpload Control like this
<ajaxToolkit:AsyncFileUpload
OnUploadedComplete="Attachment1_UploadedComplete"
OnClientUploadStarted="Attachment1_UploadStarted" runat="server"
ID="Attachment1File" AutoPostBack="true"
UploaderStyle="Traditional" CssClass="form-control"
UploadingBackColor="#CCFFFF" ThrobberID="loader1" />
I want allowed files to be doc,docx,pdf,xls,xlsx,zip and max file upload 10MB. How can I validate file before uploading?
I tried to do something like this in the codebehind but the file is already uploaded to the server when this executes
AttachmentError1.Visible = false;
string[] extension = Attachment1File.PostedFile.FileName.Split('.');
if (Attachment1File.PostedFile.ContentLength > 100000000 || !Extensions.Contains(extension[extension.Length-1]))
{
File.Delete(Server.MapPath("~/FormTemporaryFiles/") + FormId + "\\" + FormIdNumber.Value + "\\" + e.FileName.ToString());
Attachment1File.ClearAllFilesFromPersistedStore();
AttachmentError1.Visible = true;
}
Edit: I tried to use a custom validator but it didn't work.