Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jan 13, 2011 @ 11:15
    Bo Damgaard Mortensen
    0

    Multi-Node Tree Picker: set nodes programatically

    Hi all,

    Thanks for a great module for Umbraco! :)

    I'm in a situation where I'm using the Multi-Node Tree Picker datatype to let the administrator choose several media items for his news. At the moment I'm developing a "mirror-site" for his mobilephone so he's able to write news on-the-road. The only thing left on this site is to let him upload a picture (just a single picture) by using the asp FileUpload control. When the upload is done and the media item is being returned, I would like to add the media item to the Multi-Node Tree Picker datatype on the News document type. This should be done from C# aswell. 

    Is this possible at all? Any help/hint on this will be greatly appreciated! :)

    Thanks in advance,

    Bo

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jan 13, 2011 @ 11:26
    Jeroen Breuer
    1

    Hello,

    You can update the data in the property using the Document API. If you store your nodes as xml you just need to create the xml in the correct format and update the property. Read more about it here: http://our.umbraco.org/wiki/reference/api-cheatsheet/modifying-document-properties.

    If you want to store several media items in 1 picker I currently have a media picker which can do this. If you're interessted I can send the Release Candidate. Besides selecting multiple media item it also has an upload option which isn't in MNTP.

    Jeroen

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jan 13, 2011 @ 11:38
    Lee Kelleher
    0

    Hi Bo,

    As Jeroen says, you can easily set the value for MNTP programmatically.  I'd advise using CSV-based values, as it would be much easier to do - literally just assign it the media Id.

    Cheers, Lee.

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jan 13, 2011 @ 11:49
    Bo Damgaard Mortensen
    0

    Hi Jeroen,

    Thanks for your quick response! :)

    I have tried the following:

    Media m = new Media(1146);
    doc.getProperty("billeder").Value = m;
    doc.Save();
    doc.Publish(new User(0));
    umbraco.library.RefreshContent();

    Where "billeder" is the Multi-Node Tree Picker datatype. It doesn't give me any errors at all, but the media is not added to the Selected Items in the Multi-Node Tree Picker.

    Also, I've tried to set the "billeder" property to m.Id, but that doesn't work either..

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jan 13, 2011 @ 12:11
    Bo Damgaard Mortensen
    2

    O.k so I just had a peek into the database to see what data is stored when you add images/documents to the MNTP datatype. It seems it's stored as XML like:

    <MultiNodePicker>
      <nodeId>1146</nodeId>
    </MultiNodePicker>

    .. as regular text.

    I tried to do this in C#:

    string xml = "<MultiNodePicker><nodeId>" + m.Id + "</nodeId></MultiNodePicker>";
    doc.getProperty("billeder").Value = xml;

    .. and it works like a charm! :)

Please Sign in or register to post replies

Write your reply to:

Draft