Three issues with Upload control

7 posts, 0 answers
  1. Terry
    Terry avatar
    11 posts
    Member since:
    Jul 2010

    Posted 08 Nov 2010 Link to this post

    I'm using the latest internal build 2010.2.1105 and am having three problems with the upload control.  What I am trying to do is very simple. As part of a photo contest I want each user to be able to upload 1 picture.  When the picture is uploaded, I want to keep the file extension but change the filename to their userid so one user does not override another user's picture.

    First, I cannot rename the file to the userid.ext.  This used to work but no longer does.  There are two ways I have seen documented to accomplish this.  One is to set the e.UploadData.Filename in the FileUploadStarting event on the client side. I did this without error, but it seems to have no effect and the file name is not changed.  The other approach is to call e.FileParameters.Add in the FileUploadStarting event on the client to add a string value that can be retrieved in the upload handler. The call on the client seems to work, but the field is not set when it gets to the Upload handler.

    Second, an upload supposedly can be cancelled in the FileUploadStarting event by setting e.Handled to true.  When this is set to true and System.InvalidOperationException error is generated. 

    Third, I only want the user to be able to upload 1 picture.  I set the MaxFiles to 1, but even doing this the Add More Files button shows after I have selected a file.  How do I keep the Add More Files button from displaying?
  2. Terry
    Terry avatar
    11 posts
    Member since:
    Jul 2010

    Posted 09 Nov 2010 Link to this post

    I rolled back to version 2010.2.924.

    The first issue where the file name could not be changed works in this version.  So something was broken from build 924 to version 1105.

    The second issue, being able to cancel by setting e.Handled to True is not implemented in version 924. 
  3. DevCraft banner
  4. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 10 Nov 2010 Link to this post

    Hello Terry,

    Regarding your third question, this can be controlled by the IsAppendFilesEnabled property of the RadUpload. Currently, it has no relation to the MaxFileCount property, but probably we should consider synchronizing these two properties.

    The first and second issues are connected. We made some changes around the events of the RadUpload, making them routed instead of CLR events, introducing the e.Handled property in the event args. However, with the FileUploadStarting event, this lead to concurrency issues between the RadUpload and RadUploadHandler and we had to revert to the old CLR event. This is probably why the renaming of the file does not take effect. I am not able to reproduce these two issue with the latest builds. Please test these with the Q3 release dlls and let us know if these issues are resolved. If not, it would help us if you could send us a small sample that we can look into.

    We apologize for the inconveniences. 

    Kind regards,
    Alex Fidanov
    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
  5. Terry
    Terry avatar
    11 posts
    Member since:
    Jul 2010

    Posted 12 Nov 2010 Link to this post

    Alex,

    Thanks for the IsAppendFilesEnabled tip.  That does eliminate the Add More Files button

    I installed Q3. The file rename now works and setting e.Handled to true does not throw an error.

    However, it now clears the selected file when e.Handled is set to true.  I think the original intent of the request was to be able to cancel the upload for some reason (e.g. another text field was not set) and have the selected files remain selected so the other error could be fixed then the upload restarted.

  6. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 15 Nov 2010 Link to this post

    Hello Terry,

    Currently, the handling the upload starting event will cancel the upload and the upload session will be reset. If you want to cancel uploading some of the files, have you tried using the Validate event of the RadUploadItem?

    EventManager.RegisterClassHandler(typeof(RadUploadItem), RadUploadItem.ValidateEvent, new UploadValidateEventHandler(OnValidate));
      
     void OnValidate(object sender, UploadValidateEventArgs e)
    {
        if ((e.OriginalSource as RadUploadItem).FileName.Equals("Desert.jpg"))
        {
            e.ErrorMessage = "Validation failed!";
            e.Cancel = true;
        }
    }


    Kind regards,
    Alex Fidanov
    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
  7. Terry
    Terry avatar
    11 posts
    Member since:
    Jul 2010

    Posted 15 Nov 2010 Link to this post

    Thanks for the reply Alex. 

    Here is what I am trying to do.  I want to allow a user to upload an image file. Supplied with the image I need and email address and a caption for the picture. The form has three fields: Email, Caption and the image file to upload. If the user selects the file and tries to upload it without having first supplied the email address and caption, I want to stop the upload of the file, display an error message and set the focus to the missing field.

    I'd like the RadUploadControl to remember the file that was selected to upload and just let the user correct the error then press the button to restart the upload of the image.

    When I set e.Cancel=True in the FileUploadStarting event the RadUploadControl resets and clears the selected file.  This means the user has to go back and reselect the file they have already selected.

    I just want a way to stop the upload and keep the RadUploadControl in the same state is was before the button was clicked.

    Are you saying that if I put the check for a valid email address and caption in the Validate event that would allow me to set e.Cancel = true, and the control would stop the upload and keep the file in the list ready to upload?
  8. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 16 Nov 2010 Link to this post

    Hi Terry,

    Actually, you can do this in the FileUploadStarting event as well. What you can do is perform the validation there and handle the event if needed. After that, you can re-add the selected file into the RadUpload after the session is reset. I am attaching a small project with this implemented. Please let me know if you have questions on this.

    Greetings,
    Alex Fidanov
    the Telerik team
    See What's New in RadControls for Silverlight in Q3 2010 on Tuesday, November 16, 2010 11:00 AM - 12:00 PM EST or 10:00 PM - 11:00 PM EST: Register here>>
Back to Top
DevCraft banner