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

Sending custom error messages from server to the c

3 Answers 81 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Luke
Top achievements
Rank 1
Luke asked on 27 Apr 2011, 05:59 AM
Hi,

I'm currently working on uploader to sharepoint. My problem is that often when SP is down uploader still shows that everything went ok. Therefore I would like to make sure that if SP failed, (even though uploader managed to save it ok to local folder) error message is displayed. Possibly I would like to reuse uploader's error showing capabilities rather than lets say alert or error box.

I did some research and I found one person on this forum with similar issues. http://www.telerik.com/community/forums/silverlight/upload/server-cancel-upload-and-return-custom-error-message-to-client.aspx

This is my code

// HANDLER
 
 
public override bool SaveChunkData(string filePath, long position, byte[] buffer, int contentLength, out int savedBytes)
        {
            bool ret = base.SaveChunkData(filePath, position, buffer, contentLength, out savedBytes);
 
            if (base.IsFinalFileRequest() == true)
            {
                        try
                        {
                            // Moving file to SP
                        }
                        catch (Exception e)
                        {
                            Error = "Couldn't upload file to SP.";
 
                            this.AddReturnParam(RadUploadConstants.ParamNameMessage, Error);
 
                            this.AddReturnParam(RadUploadConstants.ParamNameSuccess, false);
                            this.AddReturnParam(RadUploadConstants.ParamNameFileName, this.GetFileName());
                            this.AddReturnParam(RadUploadConstants.ParamNameFinalFileRequest, true);
 
                            this.Result.Add("Error", Error);
 
                            this.SendResponse();
                        }
                    }
                    else
                    {
 
// CLIENT
 
private void FileUploader_FileUploadFailed(object sender, FileUploadFailedEventArgs e)
        {
            RadWindow.Alert(new DialogParameters
                {
                    Header = "Upload failed",
                    Content = e.HandlerData.Message
                });
             
        }

On client side e is empty with no messages at all. What am I doing wrong?

3 Answers, 1 is accepted

Sort by
0
Alex Fidanov
Telerik team
answered on 02 May 2011, 07:27 AM
Hi Luke,

Have you tried using the AddReturnFileParam method instead of AddReturnParam? Also, in your code I cannot see what value is returned from the SaveChunkData method? Are you returning true or false?

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
MD
Top achievements
Rank 1
answered on 19 Oct 2011, 04:14 PM
What would be the recommended way to return the error to the client from SaveChunkData?  If you add the below return parameters and return false from SaveChunkData the warning icon appears next to the file with issues, but the progress bar color is still green and the overall progress bar (multiple files) appears as if it is stalled under 100% and is still colored green with no indication that there was a problem.

AddReturnFileParam(RadUploadConstants.ParamNameMessage, success.Message);
AddReturnFileParam(RadUploadConstants.ParamNameSuccess, false);
AddReturnFileParam(RadUploadConstants.ParamNameFinalFileRequest, true);
0
Tina Stancheva
Telerik team
answered on 24 Oct 2011, 02:40 PM
Hi Md,

The progress bar with the overall details keeps track only of those files that passed all validations and that are valid for upload - RadUpload.CurrentSession.ValidFiles collection. This is why if one file isn't valid for upload, its size won't be included in the progress bar calculations and the ProgressBar will display only the upload progress of the items in the ValidFiles collection of the session.

Also, please keep in mind that when you validate a file in the SaveChunkData method, you have to call the base.SavaChinkData() method only after the file passes the validation. Otherwise even if the SaveChunkData method returns false, once its base method is called for the invalid file, the file will be uploaded.

All the best,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Upload
Asked by
Luke
Top achievements
Rank 1
Answers by
Alex Fidanov
Telerik team
MD
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or