Copied to clipboard

Flag this post as spam?

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


  • Scott Blomfield 16 posts 21 karma points
    Apr 08, 2009 @ 19:09
    Scott Blomfield
    0

    Getting at RelatedLinks data from C#

    I'm trying to get at the RelatedLinks data in umbraco 4.0 from C#, but the property value is empty.

    I presume there is another way to get to this data, but I haven't been able to locate that information. All the information I have been able to find (including Tim's page on Nibble.be) is about how to get to the data via XSLT.

    I'm secretly hoping that Tim might pipe up here and give me some clue as to how to get the list of links, although if anyone else has done this, I'd love a shove in the right direction! I've looked through the code for the relatedLinks control, but as best I can see it is fed its data directly from umbraco, rather than manually retrieving it?

    Does anyone have any ideas?

    Thanks,

    Scott

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Apr 10, 2009 @ 22:17
    Ismail Mayat
    0

    do you get anything in xslt, just need to ensure first of all that you have a value there.

    Regards

    Ismail

  • fed 199 posts 70 karma points
    Apr 11, 2009 @ 12:31
    fed
    0

    This should work:

    [code]
    Document d = new Document(1050);
    XmlDocument xdoc = new XmlDocument();
    xdoc.LoadXml(d.getProperty("FooterLinks").Value.ToString());

    foreach(XmlNode xnode in xdoc.DocumentElement.ChildNodes) {
    string title = xnode.Attributes["title"].Value;
    string type = xnode.Attributes["type"].Value;
    string newwindow = xnode.Attributes["newwindow"].Value;
    string link = xnode.Attributes["link"].Value;
    Response.Write(string.Format("Document: {0}, {1}, {2}, {3}", title, type, newwindow, link));
    }
    [/code]

    The above solution works against the DB so at first I thought this should work.
    Working with Node instead of Document:

    [code]
    Node node = new Node(1050);

    XmlDocument xd = new XmlDocument();
    xd.LoadXml(node.GetProperty("FooterLinks").Value);

    foreach(XmlNode xnode in xd.DocumentElement.ChildNodes) {
    string title = xnode.Attributes["title"].Value;
    string type = xnode.Attributes["type"].Value;
    string newwindow = xnode.Attributes["newwindow"].Value;
    string link = xnode.Attributes["link"].Value;
    Response.Write(string.Format("Node: {0}, {1}, {2}, {3}", title, type, newwindow, link));
    }
    [/code]

    But I only receive: Exception Details: System.ArgumentNullException: Value cannot be null. on LoadXml.. So it seems the property is null. Haven't had the time to look at it more.. have to go eat something now :)

Please Sign in or register to post replies

Write your reply to:

Draft