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.
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>
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!
Hello
what does the mediaItem.GetPropertyValue("textstringArrayAlias") return if its not XML ? :)
and what dataype have you used ?
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.
aah ofc. it is, sorry, a brianfart from my side :)
have you had a look at http://ucomponents.org/data-types/textstring-array/ ?
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.
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>
...Then to show the values:
is working on a reply...