How to add files to UploadedFilesCollection

3 posts, 0 answers
  1. Ken
    Ken avatar
    11 posts
    Member since:
    Feb 2014

    Posted 01 Mar 2016 Link to this post


    I wasn't sure how to title my thread. I have a test case that I'm not sure how to handle appropriately.

    I have the following control set up:

    <telerik:RadAsyncUpload ID="uploadControl" runat="server"
        MaxFileInputsCount="5" >


    This control is in a RadWizard that saves each step incrementally (Next/Previous click, NavigationButton Click). The RadWizard's validation is triggered on the "Finish" button. I am using the MaxFileInputsCount property to determine how many files are required to pass validation - in the case above, the control needs 5 files to be uploaded to pass field validation on the "Finish" button click.

    Here is the scenario that is causing me trouble: 

    Let's say I launch the RadWizard, go to the step with my upload control and only upload 2 of the 5 required files. I click "Next" and the 2 files are uploaded and their paths saved to the database. When I click "Finish", I get an error saying I can't submit because I need to upload 3 more files. This all works fine.

    Now, I exit and relaunch the RadWizard to complete my form, and I go to the upload control step. 

    Currently, if I upload 2 out of 5 files, exit and go back in the application, I can upload another 5 files instead of just 3. How can I re-load the AsyncUpload control and add the 2 previously-uploaded files to the UploadedFileCollection() in order for the control to know that I need 3 more files before hiding the FileInput button and so that I can validate?

    I hope that makes sense!

    I tried setting the UploadedFiles() property of the AsyncUpload control as demonstrated below, but that property is read-only...  and there is no "Add" function for the UploadeFilesCollection(), so obviously that code gives me a bunch of errors.

    Dim colFiles As Telerik.Web.UI.UploadedFileCollection()
    For Each filename In arrUploadedFiles
        Dim objFile As Telerik.Web.UI.UploadedFile
        objFile.FileName = strUploadPath & filename.ToString
    uploadControl.UploadedFiles = colFiles




    SANJAY avatar
    61 posts
    Member since:
    Jun 2012

    Posted 02 Mar 2016 in reply to Ken Link to this post


    Recommendation . When the page is reloaded, on page load check the number of files already uploaded in to the system. Not set the number of remaining file count as required files. If required display the name and details of the files already uploaded.

    Probably files cannot be added to the list of RadAsynchupload as then the control would not know that these files are not for upload but for only display.





    Sanjay Gupta

  3. Ivan Danchev
    Ivan Danchev avatar
    2188 posts

    Posted 03 Mar 2016 Link to this post

    Hello Chris,

    The AsyncUpload does not support adding files to the uploaded files collection so I would suggest using a different approach in your scenario.
    The Upload button can be hidden until 5 files are selected, then can be made visible and allow the upload of the files to the server. In addition through its PostbackTriggers property the AsyncUpload can persist the selected files across postbacks initiated by other controls, until a specific control (the hidden upload button for example) specified in the property initiates a postback. This can be used in your example, if the user uploads 2 files and does a postback, the files will not be uploaded and will be persisted until a specific button ("Upload") is clicked, and this button can be shown only when 5 files are selected.
    I attached a sample page, in order to demonstrate this scenario.

    Ivan Danchev
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top