Copied to clipboard

Flag this post as spam?

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


  • Bogdan 250 posts 427 karma points
    Aug 02, 2013 @ 13:11
    Bogdan
    0

    uComponents Textstring Array on a Media node

    Hello,

    I have a custom media type with a textstring array property and I don't know how to read the rows. The value from mediaItem.GetPropertyValue("textstringArrayAlias") is not xml.

    Any ideas?

     

    Thanks!

  • Kasper Holm 47 posts 180 karma points
    Aug 02, 2013 @ 13:16
    Kasper Holm
    0

    Hello

    what does the mediaItem.GetPropertyValue("textstringArrayAlias") return if its not XML ? :)

    and what dataype have you used ?

  • Bogdan 250 posts 427 karma points
    Aug 02, 2013 @ 13:24
    Bogdan
    0

    Hello Kasper,

    It returns a string with all the values from all the rows put togather.

    I'm not sure that you mean by "what dataype have you used"... It's a Textstring Array data type.

  • Kasper Holm 47 posts 180 karma points
    Aug 02, 2013 @ 13:34
    Kasper Holm
    0

    aah ofc. it is, sorry, a brianfart from my side :)

    have you had a look at http://ucomponents.org/data-types/textstring-array/ ?

  • Bogdan 250 posts 427 karma points
    Aug 02, 2013 @ 13:39
    Bogdan
    0

    Yes I did have a look there, but the Razor example from there does not apply on my situation, because in my case the property is on a media item, not a DynamicNode. What I tried to do, inspired by the source here https://bitbucket.org/ucomponents/ucomponents/src/a5d7f256742786dbd659c4bca941195169891cf4/uComponents.DataTypes/TextstringArray/TextstringArrayModelBinder.cs?at=5.x was to parse the xml to a List<String[]>, but I cannot get the xml.

  • Bogdan 250 posts 427 karma points
    Sep 06, 2013 @ 14:35
    Bogdan
    100

    Hi,

    My solution was to load the media item in an XPathNodeIterator by calling umbraco.library.GetMedia(). This way I can get the complete XML representing the media item. The TextstringArray XML is in there as <aliasOfTheTextstringArray><TextstringArray><values><value>...

    List<String[]> values = new List<String[]>();
    System.Xml.XPath.XPathNodeIterator xPathNodeIteratorMedia = umbraco.library.GetMedia(mediaItem.Id, true);
    
    if (!String.IsNullOrEmpty(xPathNodeIteratorMedia.Current.InnerXml))
    {
        var xml = new XmlDocument();
        xml.LoadXml(xPathNodeIteratorMedia.Current.InnerXml);
    
        foreach (XmlNode node in xml.SelectNodes("//values"))
        {
            var value = new List<String>();
    
            foreach (XmlNode child in node.SelectNodes("value"))
            {
                value.Add(child.InnerText);
            }
    
            values.Add(value.ToArray());
        }
    }
    

    Then to show the values:

    <ul>
        @foreach (String[] row in values)
        {
            <li>
                @foreach(String s in row)
                {
                    <p>@s</p>
                }
            </li>
        }
    </ul>
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies