Copied to clipboard

Flag this post as spam?

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


  • Nik Wahlberg 639 posts 1237 karma points MVP
    Jul 24, 2009 @ 18:25
    Nik Wahlberg
    0

    Resolve URLs from Related Links in C#

    Hi all,

    I have an event that I am catching to write some stuff to disk then a document is published. As part of the document type that I am using I have a type of Related Links that will allow the contributor to either select an internal page OR link to something external. How would i go about getting the actual link value from this datatype in c#? Should I be using XPath? If so, it would be great to see an example of iterating the values.

    Thanks much!

    -- Nik

  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Jul 25, 2009 @ 07:46
    Richard Soeteman
    2

    Hi Nik,

    When you loop thorugh the related links this will return the Id's. Then you can use the umbraco.library.NiceUrl method to get the relative url. You only have to prefix this with the url of the site.

    Simple example how I made relative url's absolute to use to mail links to cusomers

    string

     

    domain = HttpContext.Current.Request.ServerVariables["SERVER_NAME"];

    return

     

    string.Format("http://{0}{1}", domain, umbraco.library.NiceUrl(nodeId));

     

    Hope this helps you,

    Richard

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Jul 25, 2009 @ 13:03
    Nik Wahlberg
    0

    sweet, I will try this out. Although it doesn't look like I am getting IDs back right now. That is probably another issue though...

    Thanks,
    Nik

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Jul 27, 2009 @ 16:33
    Nik Wahlberg
    0

    Hi Ricahrd, I mesread your response. The problem that I have is that I am not getting any values back for that data type right now at all (eventhough I have selected and added links to the element). So, I guess my question is more, is there a data strcture that I need to access in order to be able to read the values that are added to the related links datatype as part of a given node. The XSLT is clear on how to access this item, but I am confused as to how to do this in c#.

    Thanks,
    Nik

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 27, 2009 @ 17:04
    Dirk De Grave
    0

    Nik,

     

    Output the value of the property using <xsl:copy-of select="aliasOfRelatedLinksProperty" /> and have a look at the source of the rendered html.

    Must be something along the lines of:

     

    <links><link title="TITLE" link="ID" type="internal|external" newwindow="0|1" /></links>

     

    How about

     

    <xsl:for-each select="data [@alias = 'aliasOfRelatedLinksProperty']/links/link>
      <a href="{@link}"><xsl:value-of select="@title" /></a>
    </xsl:for-each>

     

    Have to do some <xls:if>'s as well to check whether it's an internal/external link!

     

    Cheers,

    /Dirk

     

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Jul 27, 2009 @ 17:30
    Nik Wahlberg
    0

    Yeah, I have the XSLT down...but in this instance I need to access the value in an Event Handler. I guess my confusion is how to accomplish this in c#. I was inspecting the nodeFactory and didn't come up with a solution. I am sure I will be kicking myself when I see the answer....but for now I am at a dead end.

    Thanks again,
    Nik

  • Comment author was deleted

    Jul 27, 2009 @ 17:42

    Hi Nik,

    Haven't tried this, but I would load the value of the related link property in an xml document

    string xml = //the value;
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(new StringReader(xml));

    And then you should be able the different links.

    xmlDoc.SelectNodes("/links/link");

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Jul 28, 2009 @ 15:03
    Nik Wahlberg
    0

    Tim, that looks good. I will give this a try.

    Thanks for chiming in!

Please Sign in or register to post replies

Write your reply to:

Draft