How do I get UploadAttachments events to fire for server-side validation prior to upload?

  •  02-24-2012, 3:24 PM

    How do I get UploadAttachments events to fire for server-side validation prior to upload?

    Using the standard .net upload control, I can do this:
     
        Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
     
              Dim fname As String = FileUpload1.FileName
     
              'Here I can do some validation on the file type
               If fname.EndsWith(".jpg") Then
              
                       'I can also augment the file name prior to uploading, like this:
                       fname = Now.ToString("yyyyMMdd-HHMMss-") & fname
     
                      'After validation and file name augmentation, I can then choose to upload the file:
                      FileUpload1.SaveAs(Server.MapPath("~/files/") & fname
     
             Else
                      'Inform user that file must be of type .jpg
     
             End If
     
        End Sub
     
     
    I just want to duplicate this simple behavior with the Ajax Uploader.  Is this possible? 
     
    In the example above, I can do the validation BEFORE the upload ever occurs.  I tried to do this with the Ajax Uploader but when calling UploadAttachments1.Upload manually, I'm required to send the file name, file size, and temp path, which I can't seem to get from the control.  I learned in another post how to retrieve the file name, size, path AFTER upload or via Javascript prior to upload, but neither of these options give me the ability to do simple server-side validation as in the example above.  I see several events such as AttachmentAdded, AttachmentClicked, AttachmentDataBound, etc. but I am unable to get any of these to fire (except for AFTER the file has been uploaded).
     
    I seem to be running in circles.
     
    Is there any way to duplicate the simplicity of the code above with the Ajax Uploader?  
     
    Thank you.
View Complete Thread