OnClientFileUploading question

3 posts, 0 answers
  1. Bob
    Bob avatar
    46 posts
    Member since:
    Apr 2012

    Posted 05 Sep 2013 Link to this post

    Thanks all in advance.

    We understand how the set_cancel method works within the OnClientFileUploading event.  However, we need to confirm the behaviour when set_cancel(true) is executed.  Does it cancel all the files in a multiple file upload or just the one file?

    Also, we would like to do some custom validation within the OnClientFileUploading event but need to get the file extension in order to do this.  We see how to issue args.get_fileName() but need to inspect the extension based on our own invalid extension list.  Is there a file extension method available for this?

    Thanks...Bob Baldwin
    Trabon Solutions
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Sep 2013 Link to this post

    Hi Bob,

    The OnClientFileUploading client-side event occurs when each file has started uploading. To make it more clear suppose you are selecting five files to upload, then this event will fire prior to uploading each file. If you are simply giving set_cancel(true) inside the OnClientFileUploading method, then set_cancel(true) will be executed each time when the OnClientFileUploading event fires and as a result all the uploading get cancelled.

    Please have a look at the following JavaScript I tried to extract the file extension from the file name and cancel the upload of files with extensions other than "jpg".

    JavaScript:
    <script type="text/javascript">
        function OnClientFileUploading(sender, args) {
            var fileextension = args.get_fileName().split('.').pop();
            if (fileextension != "jpg") {
                args.set_cancel(true);
            }
            else {
                args.set_cancel(false);
            }
        }
    </script>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bob
    Bob avatar
    46 posts
    Member since:
    Apr 2012

    Posted 06 Sep 2013 Link to this post

    Thanks Shinu,

    That answered our questions.

    Bob Baldwin
    Trabon Solutions
Back to Top