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

Add more files functionality and custom parameters

11 Answers 185 Views
Upload
This is a migrated thread and some comments may be shown as answers.
dan
Top achievements
Rank 1
dan asked on 10 Sep 2009, 08:55 AM
Hi,
I am trying to develop an application using RadUpload.
I want to send custom parameters together with each file upload,
but when I hit the "Add more files" button, all previously inserted custom parameters are cleared,
while previously selected files are still there.
Could you please help me preventing this behaviour, and keep the custom parameters?

Thank you in advance
dan

11 Answers, 1 is accepted

Sort by
0
Ivan
Telerik team
answered on 10 Sep 2009, 01:17 PM
Hello Daniela,

Thank you for contacting us.

The issue you reported looks very strange. We prepared and tested the upload control in a small application and everything seems to be OK. Attached you can find this application. Please give it a try and let us know if the issue still persists.

More information about custom parameters you can find in our documentation.

Greetings,
Ivan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Luca Mazzi
Top achievements
Rank 2
answered on 10 Sep 2009, 01:56 PM
Hi Ivan,
thank you for your reply.

I am afraid I didn't explain my problem properly.
Actually I have two TextBoxes and a CheckBox for each file to be uploaded, where the user can input information about the file being uploaded.
The problem is that if I add more files to the list, all previously filled in text and check boxes are cleared.

I was also trying to use a RadioButton as an input parameter for each file, but I wasn't able to make it work properly,
since there is one only GroupName which allows only one radio at a time to be checked.

Maybe the two problems are related to the same issue?


0
dan
Top achievements
Rank 1
answered on 10 Sep 2009, 02:09 PM
Sorry Ivan,
I used my support login to reply, indeed it was me answering ;-)

0
stacy cook
Top achievements
Rank 1
answered on 15 Dec 2009, 03:45 PM
We are looking to give the user the ability to set the names of the files selected for uploading in the upload control and from Dan's post, it sounds like we would have an issue.
Has the solution for Dan's issue been found?

Thanks!
0
dan
Top achievements
Rank 1
answered on 16 Dec 2009, 09:36 AM
Hi stacy,
thank you for your interest in the issue I posted :-)

No, there is no solution for this problem yet, the issue is due to the clearing of collections when more files are added to the control.
The only workaround is to disable the "Add more files" button.

0
Kevin Hendriks
Top achievements
Rank 1
answered on 14 Jan 2010, 01:00 PM
Hey, I am planning to do something similar with aditional parameters, has the issue you discribe been resolved?
0
Ivan
Telerik team
answered on 14 Jan 2010, 02:52 PM
Hello Kevin,

The "Add more files" still uses the old mechanism, i.e. all items' containers will be recreated. Because of this you should avoid the add more files interface.

Best wishes,
Ivan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Richard Weissenberg
Top achievements
Rank 1
answered on 20 Aug 2010, 11:30 AM
Hi,

I am trying to add the same functionality to the upload items - a description field and perhaps more. I have the text box rendering but not too sure how to access them or when to access them. I want to send files and corresponding description back to the server but need to access the data on the client side first.

Also, I am using 2010_2 - the Items re-render when appending files still.

Any help accessing my description fields will be appreciated.

Thanks
0
Tina Stancheva
Telerik team
answered on 25 Aug 2010, 11:15 AM
Hi Richard Weissenberg,

During the past months the RadUpload control was improved. More information you can find here.

Here are the breaking changes for the control:
------------------------------
RadUploadHandler:

If there is no custom handler the default setup will work out of the box.
If a custom handler is implemented the following changes should be performed:

  • When the ProcessStream()  method is overridden the logic should be placed in the SaveChunkData() override.
  • The way the parameters are passed to the handler is changed, and the usage of this.Request.Form[paramName] should be replaced withthis.GetQueryParameter(paramName)
------------------------------

Also, I attached a sample project illustrating how you can upload files and add custom file parameters to each uploaded file. Also in the SampleUploadHandler, the GetFileName() method is overridden to use the passed from the client parameter to create new name for each file.

I hope this information will help. However, if you need further assistance, please let us know.

Greetings,
Tina Stancheva
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Richard Weissenberg
Top achievements
Rank 1
answered on 27 Aug 2010, 11:10 AM
Hi Tina,

Thanks for your help. I did manage to get the description data from the extra textboxes I added on the client side:

Used code like this:
private void RadUploadControl_UploadStarted(object sender, UploadStartedEventArgs e)
{
    SaveFileDescriptionsToDictionary();
}


void SaveFileDescriptionsToDictionary()
{
     
    int index = 0;
    foreach (RadUploadItem item in RadUploadControl.Items)
    {
    var descriptionTextBox = item.FindChildByType<TextBox>();
    if (descriptionTextBox != null)
    {
        string description = descriptionTextBox.Text;
        if (!fileDescriptions.ContainsKey(item.FileName))
        {
        //RadUploadControl.AdditionalPostFields.Add("Description_" + index, description);
        fileDescriptions.Add(item.FileName, description);
        index++;
        }
    }
    }
}

Another issue I ran into related to sending custom data back to the client:

Files are saved on the server, but I rename the files before saving with a guid. I want to send the new file name guid and the old file name back to the client.

What I find is that when overriding the property GetAssociatedData() it works as expected using code like this:
in the handler:
private Dictionary<string, object> dictionary = new Dictionary<string, object>();
public override Dictionary<string, object> GetAssociatedData()
{
    dictionary.Add(GetFileName(), newFileName);
    return dictionary;
}

and on the client:
private void RadUploadControl_FileUploaded(object sender, FileUploadedEventArgs e)
{
    //function is called for every file uploaded...but e.HandlerData.CustomData is only completely populated on the last file uploaded
 
    if (RadUploadControl.Items.Count == e.HandlerData.CustomData.Count)
    {
    //save uploaded file names to dictionary
    foreach (RadUploadItem item in RadUploadControl.Items)
    {
        object uploadedFileName = "";
        e.HandlerData.CustomData.TryGetValue(item.FileName, out uploadedFileName);
        if (uploadedFileName != null)
        {
        SaveUploadedFileNamesToDictionary(e.SelectedFile.Name, uploadedFileName as string);
        }
    }
 
    }
}

If you look closely at the client side handling you will notice I wait for:
if (RadUploadControl.Items.Count == e.HandlerData.CustomData.Count)
because the CustomData is not completely populated until the last fileUploaded event is fired. This is not intuitive and I would be interested in a cleaner way.

Just thought I post my results as it might help someone else along the way.

Thanks

I have a sample app if anyone is interested.
0
Kiril Stanoev
Telerik team
answered on 01 Sep 2010, 03:09 PM
Hello Richard ,

Thank you for sharing your experience. Let us know if you encounter any further issues. We'd be glad to assist you.

Greetings,
Kiril Stanoev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
Upload
Asked by
dan
Top achievements
Rank 1
Answers by
Ivan
Telerik team
Luca Mazzi
Top achievements
Rank 2
dan
Top achievements
Rank 1
stacy cook
Top achievements
Rank 1
Kevin Hendriks
Top achievements
Rank 1
Richard Weissenberg
Top achievements
Rank 1
Tina Stancheva
Telerik team
Kiril Stanoev
Telerik team
Share this question
or