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

Three issues with Upload control

6 Answers 152 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Terry
Top achievements
Rank 1
Terry asked on 08 Nov 2010, 02:12 PM
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?

6 Answers, 1 is accepted

Sort by
0
Terry
Top achievements
Rank 1
answered on 09 Nov 2010, 02:34 PM
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. 
0
Alex Fidanov
Telerik team
answered on 10 Nov 2010, 03:31 PM
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
0
Terry
Top achievements
Rank 1
answered on 12 Nov 2010, 02:07 PM
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.

0
Alex Fidanov
Telerik team
answered on 15 Nov 2010, 01:25 PM
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
0
Terry
Top achievements
Rank 1
answered on 16 Nov 2010, 12:48 AM
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?
0
Alex Fidanov
Telerik team
answered on 16 Nov 2010, 01:52 PM
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>>
Tags
Upload
Asked by
Terry
Top achievements
Rank 1
Answers by
Terry
Top achievements
Rank 1
Alex Fidanov
Telerik team
Share this question
or