This is a migrated thread and some comments may be shown as answers.

Prevent file from uploaded

2 Answers 110 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
jnh999
Top achievements
Rank 1
jnh999 asked on 29 Jan 2014, 09:02 PM
I need to continue/stop file upload to server based the validation logic.  If file passed validation,the file can be uploaded to server, otherwise stop the upload.  Can this be done with RadAsyncUpload?  If yes, can anyone show some sample code?
Thanks for any help.

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Jan 2014, 04:10 AM
Hi,

You can handle the OnClientFileUploading event of RadAsyncupload, check the validation logic and if it fails you can cancel the upload by setting args.set_cancel(true) as follows.

ASPX:
<telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server"   OnClientFileUploading="OnClientFileUploading1" TargetFolder="Examples">
</telerik:RadAsyncUpload>

JavaScript:
<script type="text/javascript">
    function OnClientFileUploading1(sender, args) {
        //check validation logic and if it fails
        args.set_cancel(true);
    }
</script>

Let me know if you have any concern.
Thanks,
Shinu.
0
jnh999
Top achievements
Rank 1
answered on 30 Jan 2014, 04:00 PM

Shinu,

Thanks for your reply.  But my validation logic is on the server side.  How can client side get to know the result of validation.  Basically, I need to validate the uploaded file which is an excel file before allowing file to be uploaded to the server.

I think what I can do is to use the custom asyncUploadHandler and call validation class in the handler.  then if validation failed, not continue on process the file and hope I can stop the file upload that way.

protected override IAsyncUploadResult Process(UploadedFile file, HttpContext context, IAsyncUploadConfiguration  configuration, string tempFileName)
 {
    CustomAsyncUploadResult result = CreateDefaultUploadResult<CustomAsyncUploadResult>(file);
    bool bAuditSuccess = auditClass.Audit();
  
    if (bAuditSuccess)
    {
          return base.Process(file, context, configuration, tempFileName);
    }
    else
    {
          result = CreateDefaultUploadResult<CustomAsyncUploadResult>(file);
    }
    return result;
}

I hope this works.

 

Tags
AsyncUpload
Asked by
jnh999
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
jnh999
Top achievements
Rank 1
Share this question
or