RadasyncUpload maxfileinput and invalid files

2 posts, 0 answers
  1. Rakesh
    Rakesh avatar
    23 posts
    Member since:
    May 2013

    Posted 20 Aug 2014 Link to this post

    Hi
    I am facing an issue with this control. Any help is much appreciated.Below is my requirement
    I have to allow maximum of 3 valid files to be uploaded so I set MaxFileInputsCount=3. Now I have some clientside validations and if the files are invalid I am removing them and I cannot see the files in UI but the upload control is not getting back to its original state. Lets say I upload a file and if it is valid I stream it to my DB. Now the count is 1 . I try again with another file and it is not a valid file then I show a message to the user and after the next upload the which is a valid file I am not seeing the upload control. EVen though I have just 2 files uploaded , the control is disappearing. Can anyone help me to resolve this issue. below is my script

    function onClientFileUploading(sender, args) {
        debugger;
        var message = "";
        var errorWithFile = false;
        var regEx = /[~#%&*{}:<>?\/|\'\"]/;

        //Invalid Characters in File Name
        if (regEx.test(args.get_fileName())) {
            message = "File: " + args.get_fileName() + " contains invalid characters.  It has not been uploaded.  Please rename the file and upload again.";
            errorWithFile = true;
        }

        //Duplicate File Validation
        for (var fileindex in sender._uploadedFiles) {
            if (sender._uploadedFiles[fileindex].fileInfo.FileName == args.get_fileName()) {
                message = "You have already uploaded a file with the name " + args.get_fileName() + ". Please rename your new file and upload again.";
                errorWithFile = true;
                break;
            }
        }

        if (errorWithFile) {
            --filesSelected;
            args.set_cancel(true);
            sender._cancelUpload(args.get_row());
            sender._updateCancelButton(args.get_row());
            var index = $(args.get_row()).index();
            sender.deleteFileInputAt(index);
            sender.updateClientState();        
            alert(message);
        }
        MonitorFileUploadingQueue();
    }

    function onClientValidationFailed(sender, args) {
        var message = "";
        var errorWithFile = false;

        //File Extension Validation
        if (!sender.isExtensionValid(args.get_fileName())) {
            message = "File: " + args.get_fileName() + " selected has an invalid extension.";
            errorWithFile = true;
        }
        //MAX File Size
        else {
            message = "File: " + args.get_fileName() + " has exceeded the " + sender._maxFileSize / 1048576 + " MB file size limit.";
            errorWithFile = true;
        }

        if (errorWithFile) {
            debugger;
            --filesSelected;        
            var index = $(args.get_row()).index();
            sender.deleteFileInputAt(index);
            sender.updateClientState();
            
            alert(message);
        }

        MonitorFileUploadingQueue();
    }

    function MonitorFileUploadingQueue() {
        if (filesUploaded == filesSelected) {
            EnableDisableSubmitButton(true, "");
        }
        else {
            EnableDisableSubmitButton(false, "Uploading Files...");
        }
    }

    Thanks
    Rakesh
  2. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 26 Aug 2014 Link to this post

    Hi Rakesh,

    Probably the files disappeared, because you are making a postback and files are submitted. Try to use Custom Handler. Sample is attached.


    To limit the number of the uploaded files you may use something like this:

    function onClientFileUploading(sender, args) {
     
        //Check the number of the uploaded files
        if (sender.getUploadedFiles().length > 3) {
            //Cancel file uploading
            args.set_cancel(true);
        }
    .....

    Regards,
    Hristo Valyavicharski
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top