Add more files functionality and custom parameters

12 posts, 0 answers
  1. dan
    dan avatar
    4 posts
    Member since:
    Mar 2009

    Posted 10 Sep 2009 Link to this post

    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
  2. Ivan
    Admin
    Ivan avatar
    519 posts

    Posted 10 Sep 2009 Link to this post

    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.
  3. DevCraft banner
  4. Luca Mazzi
    Luca  Mazzi avatar
    2 posts
    Member since:
    Mar 2009

    Posted 10 Sep 2009 Link to this post

    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?


  5. dan
    dan avatar
    4 posts
    Member since:
    Mar 2009

    Posted 10 Sep 2009 Link to this post

    Sorry Ivan,
    I used my support login to reply, indeed it was me answering ;-)

  6. stacy cook
    stacy cook avatar
    3 posts
    Member since:
    Nov 2009

    Posted 15 Dec 2009 Link to this post

    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!
  7. dan
    dan avatar
    4 posts
    Member since:
    Mar 2009

    Posted 16 Dec 2009 Link to this post

    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.

  8. Kevin Hendriks
    Kevin Hendriks avatar
    56 posts
    Member since:
    Feb 2009

    Posted 14 Jan 2010 Link to this post

    Hey, I am planning to do something similar with aditional parameters, has the issue you discribe been resolved?
  9. Ivan
    Admin
    Ivan avatar
    519 posts

    Posted 14 Jan 2010 Link to this post

    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.
  10. Richard Weissenberg
    Richard  Weissenberg avatar
    11 posts
    Member since:
    Jun 2009

    Posted 20 Aug 2010 Link to this post

    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
  11. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 25 Aug 2010 Link to this post

    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
  12. Richard Weissenberg
    Richard  Weissenberg avatar
    11 posts
    Member since:
    Jun 2009

    Posted 27 Aug 2010 Link to this post

    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.
  13. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 01 Sep 2010 Link to this post

    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
Back to Top
DevCraft banner