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.
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
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#.
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.
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
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
Hope this helps you,
Richard
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
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
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:
How about
Have to do some <xls:if>'s as well to check whether it's an internal/external link!
Cheers,
/Dirk
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
Hi Nik,
Haven't tried this, but I would load the value of the related link property in an xml document
And then you should be able the different links.
xmlDoc.SelectNodes("/links/link");
Tim, that looks good. I will give this a try.
Thanks for chiming in!
is working on a reply...