///<summary>/// Resolves the value of an Embedded Content datatype to a .NET collection///</summary>///<param name="embeddedContentXml">The value of the Embedded Content in XML format</param>///<returns>A collection of items with properties</returns>publicstaticIEnumerable<IEnumerable<KeyValuePair<string, string>>> ResolveEmbeddedContent(string embeddedContentXml)
{
XmlDocument xmlDoc = newXmlDocument();
xmlDoc.LoadXml(embeddedContentXml);
foreach (XmlNode node in xmlDoc.SelectNodes("//data/item"))
{
List<KeyValuePair<string, string>> properties = newList<KeyValuePair<string, string>>();
foreach (XmlNode property in node.SelectNodes("*"))
{
properties.Add(newKeyValuePair<string, string>(property.Name, property.InnerText));
}
yieldreturn properties;
}
}
I was using the embedded content control in Umbraco. I wanted to read the data in .NET. I have seen your code but I was wondering how can we get the embedded content XML into .NET. Can you please post the full code example.
I was using this productNode.GetProperty("embeddedVariant").Value; to get the value and I am getting the embedded content data as: SWhite1000SRed1001MGreen1002
(which is nothing but 1. Size: S, Color: White, Value: 1000
2. Size: S, Color: Red, Value: 1001
3. Size: M, Color: Green, Value: 1002)
When I retrieve the values I wanted to get the values as key value pairs as you mentioned in the example.
Embedded Content in codebehind, get all properties?
Im using currentNode.GetProperty().Value to get the value from my Embedded Content but how do I get all the properties?
I have "image", "text" and "link" set but I don't have a clue how to loop through all the images and print out the properties.
Help please..
Btw, here's an exampje of how to use this:
Hello,
I was using the embedded content control in Umbraco. I wanted to read the data in .NET. I have seen your code but I was wondering how can we get the embedded content XML into .NET. Can you please post the full code example.
Thanks,
Subba.
Well just use:
I was using this productNode.GetProperty("embeddedVariant").Value; to get the value and I am getting the embedded content data as: SWhite1000SRed1001MGreen1002
(which is nothing but 1. Size: S, Color: White, Value: 1000
2. Size: S, Color: Red, Value: 1001
3. Size: M, Color: Green, Value: 1002)
When I retrieve the values I wanted to get the values as key value pairs as you mentioned in the example.
Here is the embedded content screenshot:
Hi Rao,
Im using the "productNode.GetProperty("embeddedVariant").Value" and I get the following:
<data><item id="1"><TestName propertyid="1">Available colours</TestName><TestValue propertyid="2">yellow, green, purple, orange</TestValue><TestLinkedMediaItem propertyid="3">1093</TestLinkedMediaItem><TestLinkedContentItem propertyid="4">1070</TestLinkedContentItem><TestValidFrom propertyid="5">2012-03-13 15:46</TestValidFrom></item><item id="3"><Name propertyid="1">package measurments</Name><Value propertyid="2">50x80x40</Value><LinkedMediaItem propertyid="3">1097</LinkedMediaItem><LinkedContentItem propertyid="4">1068</LinkedContentItem><ValidFrom propertyid="5">2012-03-31 06:13</ValidFrom></item><item id="2"><Name propertyid="1">package weight</Name><Value propertyid="2">50k</Value><LinkedMediaItem propertyid="3">1092</LinkedMediaItem><LinkedContentItem propertyid="4">1064</LinkedContentItem><ValidFrom propertyid="5">2020-03-11 17:40</ValidFrom></item></data>
Any suggestions on why do I get the tags as well?
Many thanks
Mkariti
Ok So I think I've got it - If someone knows better way how to extract the node's property would love to see it.
Here is my code:
}Regards,
For Displaying String out of HTML.
is working on a reply...