Prevent file from uploaded

3 posts, 0 answers
  1. jnh999
    jnh999 avatar
    29 posts
    Member since:
    Apr 2010

    Posted 29 Jan 2014 Link to this post

    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. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 Jan 2014 in reply to jnh999 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. jnh999
    jnh999 avatar
    29 posts
    Member since:
    Apr 2010

    Posted 30 Jan 2014 in reply to Shinu Link to this post

    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.

     

Back to Top