0

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.

Georgia Kalyva
  • 737
  • 2
  • 9
  • 23

1 Answers1

0

What I did is add the code to the codebehind in the UploadedCompleted Event of the AsyncFileUpload and chech again at the button submit. Custom Validator did not work, so I had to do it manually.

Georgia Kalyva
  • 737
  • 2
  • 9
  • 23