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

How to add files to UploadedFilesCollection

2 Answers 349 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Ken
Top achievements
Rank 1
Ken asked on 01 Mar 2016, 04:21 PM

Hello!

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"
    Skin="MetroTouch"
    UseApplicationPoolImpersonation="true"
    AutoAddFileInputs="true"
    InitialFileInputsCount="1"
    EnableInlineProgress="true"
    MultipleFileSelection="Automatic"
    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
    colFiles.Add(objFile)
Next
uploadControl.UploadedFiles = colFiles

 

 

 

2 Answers, 1 is accepted

Sort by
0
SANJAY
Top achievements
Rank 1
answered on 02 Mar 2016, 02:53 PM

Hi

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.

 

Regards

 

 

Sanjay Gupta

0
Ivan Danchev
Telerik team
answered on 03 Mar 2016, 08:48 AM
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.

Regards,
Ivan Danchev
Telerik
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
Tags
AsyncUpload
Asked by
Ken
Top achievements
Rank 1
Answers by
SANJAY
Top achievements
Rank 1
Ivan Danchev
Telerik team
Share this question
or