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

returning custom parameters to client after upload

7 Answers 79 Views
Upload
This is a migrated thread and some comments may be shown as answers.
coding
Top achievements
Rank 1
coding asked on 27 Apr 2011, 06:21 PM
Greetings,

We are trying to return a list of custom objects after each file has been uploaded and processed on the server but for some reason on the client side we are not able to cast the object back into the List<CustomObject>.  Instead it looks like the object is not serialized and is simply returning the original object name as a string.  Should this be possible?

here's the code on the server:

 

public override Dictionary<string, object> GetAssociatedData()
{
    Dictionary<string, object> dict = base.GetAssociatedData();
    if (this.IsFinalFileRequest())
    {
        List<CustomObject> list = new List<CustomObject>();
        dict.Add("customObjectList", list);
    }
    return dict;
}

here's the relevant code on the client:

radUpload.FileUploaded += (s, e) =>
{
    List<CustomObject> objList = e.HandlerData.CustomData["customObjectList"] as List<CustomObject>;
      
};

Thanks for your help!


7 Answers, 1 is accepted

Sort by
0
Alex Fidanov
Telerik team
answered on 28 Apr 2011, 08:14 AM
Hello coding,

You are right, the RadUpload(Handler) does not serialize objects when they are passed as parameters. You can send only strings (essentially, the control will call the ToString() method). If you want to return data of another type, you would have to use an external channel(service) to do so.

Best wishes,
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
coding
Top achievements
Rank 1
answered on 28 Apr 2011, 09:14 PM
Thanks Alex, one more quick question.  Instead of passing the object back we tried to serialize it to xml and found another problem.

Here's the code snippet:

Dictionary<string, object> dict = base.GetAssociatedData();
try
{                
    if (this.IsFinalFileRequest())
    {
        dict.Add("NewFileName", "fdsfds\"fdsfds");
    }
}
catch (Exception ex)
{
}

If there is a " (double quote) in the string being returned the FileUploaded event is never called.  This code executes fine without throwing an exception but as mentioned on the client side nothing happens.  If I take the \" out of the string above everything works as expected AND the FileUploaded event is fired.

I forgot to mention we are using your latest internal build (01219RadControls_for_Silverlight_4_2011_1_0411_DEV_hotfix) because there was a problem with the RadContextMenu working with the ChildWindow.  I'm not sure if this is part of the problem.

Thanks!
0
Alex Fidanov
Telerik team
answered on 03 May 2011, 05:15 PM
Hello coding,

The RadUploadHandler will try to convert this string into a Json format string, so perhaps the problem comes from there. What you can do is to encode/decode the string - for example the url encoding. Similar to what I am suggesting is the UrlEncode method.

dict.Add("NewFileName", this.Context.Server.UrlEncode("fdsfds\"fdsfds"));

or the System.Windows.Browser.HttpUtility class. The trick here is that one is not available in Silverlight and the other on the server, but you can definitely use this approach.

Best wishes,
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
Richard Weissenberg
Top achievements
Rank 1
answered on 27 Jan 2012, 02:46 PM
"You can send only strings (essentially, the control will call the ToString() method)"

I just have to vent some frustration with this statement! Both the docs and api:
Dictionary<stringobject> dict = base.GetAssociatedData();

both allude to the fact that you can pass objects back. It should be made clearer that only strings can be passed back.

Is there a sample project  or blog that deals with a neat way to serialize a business object on the server and pass it back via the handler to be deserialized on the client. The serialization engine is different on client and server so it is not a simple task.

0
Alex Fidanov
Telerik team
answered on 01 Feb 2012, 03:35 PM
Hello.

I apologize for the confusion. Indeed, this declaration suggests that you can pass custom objects. However, the RadUpload control does not have a built-in serialization mechanism able to serialize and deserialize a custom object. At this moment, only strings are allowed to be transported between client and the server. You can try a XmlSerializer or custom xml serialization.

Could you please give us more information on what objects to do want to pass to the server and back?

Best wishes,
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
Richard Weissenberg
Top achievements
Rank 1
answered on 02 Feb 2012, 08:34 AM
Hi Alex,

Thanks for the response. I have implemented object JSON serialization in the handler and then deserialized on the client. This works.

These are just business objects - something like a File data transfer object is used to store all of the file's metadata. This is persisted to the database and referenced by other objects in the system.

This is not a major problem since you can just transfer the bare minimum (file name and location) to the client and it can make another service call to post process the uploaded file (i.e. save the metadata, thumbnail or whatever).

Now to tackle the lack of WCF-like security...

Thanks
0
Alex Fidanov
Telerik team
answered on 07 Feb 2012, 09:35 AM
Hello,

Perhaps, you can try the approach that the upload control itself is using. It also needs to pass several parameters to the server and back - like the file name, target folder, etc. If you could represent your business objects as a collection of flat properties, you can pass each property as a different entry in the associated data dictionary.

Regards,
Alex Fidanov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
Upload
Asked by
coding
Top achievements
Rank 1
Answers by
Alex Fidanov
Telerik team
coding
Top achievements
Rank 1
Richard Weissenberg
Top achievements
Rank 1
Share this question
or