returning custom parameters to client after upload

8 posts, 0 answers
  1. coding
    coding avatar
    6 posts
    Member since:
    Apr 2011

    Posted 27 Apr 2011 Link to this post

    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!


  2. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 28 Apr 2011 Link to this post

    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
  3. DevCraft banner
  4. coding
    coding avatar
    6 posts
    Member since:
    Apr 2011

    Posted 28 Apr 2011 Link to this post

    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!
  5. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 03 May 2011 Link to this post

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

    Posted 27 Jan 2012 Link to this post

    "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.

  7. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 01 Feb 2012 Link to this post

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

    Posted 02 Feb 2012 Link to this post

    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
  9. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 07 Feb 2012 Link to this post

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