and then traversing the XmlDocument. However, I cannot use C# and the API to create the field in the first place.I am using code that looks like:
// Create XmlDocument to hold products
doc = newXmlDocument();
// Insert declaration as first nodeXmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", null, "yes");
doc.AppendChild(declaration);
// Create the root node
rootElement = doc.CreateElement("links");
doc.AppendChild(rootElement);
// Look up the Product Idint productId = productsXref[thisProduct];
// Add Product link to current Part
linkElement = doc.CreateElement("link");
rootElement.AppendChild(linkElement);
// Link Type is internal
linkAttribute = doc.CreateAttribute("type");
linkAttribute.Value = "internal";
linkElement.SetAttributeNode(linkAttribute);
// Link Title
linkAttribute = doc.CreateAttribute("title");
linkAttribute.Value = thisProduct;
linkElement.SetAttributeNode(linkAttribute);
// Link Link
linkAttribute = doc.CreateAttribute("link");
linkAttribute.Value = productId.ToString();
linkElement.SetAttributeNode(linkAttribute);
// Link NewWindow
linkAttribute = doc.CreateAttribute("newwindow");
linkAttribute.Value = "1";
linkElement.SetAttributeNode(linkAttribute);
DocumentBeingWorkedOn.getProperty("relatedLink").Value = doc;
The last statement above consistently fails with nul object exception.
Sorry but I am no longer using the version of Umbraco where I experienced this problem. I suggest you re-post your query because after three years I cannot find the code where I had the problem.
Using c# to create a RelatedLinks field
I can retrieve the contents of a relatedlinks field by creating an XmlDocument from the returned value as below:
and then traversing the XmlDocument. However, I cannot use C# and the API to create the field in the first place.I am using code that looks like:
The last statement above consistently fails with nul object exception.
Can anyone help? I'm new to Umbraco.
hey dude did u figure this out yet??
I am having the same problem.. I am not able to set/add value to my RelatedLinks field programatically! :s
Hi Ehsan
Sorry but I am no longer using the version of Umbraco where I experienced this problem. I suggest you re-post your query because after three years I cannot find the code where I had the problem.
Good luck!
Mike
is working on a reply...