I have an RTE and then it is selected using the Hyperlink option (i know i may need to amend the string to have it in the format umb://xx/yyyy but thats fine)
RTE is rendered as text and the links do work on the public end.
I need to get the link converted so i can take other actions so for this i just need to convert the Umb URL into the link it converts to which would help.
var url = string.Empty;
if (Udi.TryParse("umb://document/123456", out var udi))
{
var content = Umbraco.Content(udi);
if (content != null)
{
url = content.Url();
}
}
In C# classes you can do the following.
var url = string.Empty;
if (Udi.TryParse("umb://document/123456", out var udi))
{
var contextAccessor = Current.Factory.GetInstance<IUmbracoContextAccessor>();
var context = contextAccessor.UmbracoContext;
var content = context.Content.GetById(udi);
if (content != null)
{
url = content.Url();
}
}
You can also inject the IUmbracoContextAccessor instead of using Current to get it.
Convert Udi to URL?
Hi
I select a node in Umbraco. This saves it as
I would like to convert this to the equivalent URL. How could i do that?
I tried
as per the many threads on similair questions to this but this doesnt display the corresponding URL that im after to the page, media etc etc
Hi J,
What type of property editor are you using for the selecting a node ?
Dave
Hi
I have an RTE and then it is selected using the Hyperlink option (i know i may need to amend the string to have it in the format umb://xx/yyyy but thats fine)
Thanks
Hi J,
How are you rendering your RTE ? Umbraco should take of setting the correct url for links in a RTE.
Dave
Hi Dave
RTE is rendered as text and the links do work on the public end.
I need to get the link converted so i can take other actions so for this i just need to convert the Umb URL into the link it converts to which would help.
Thanks
Hi J,
Can you explain what you are trying to achieve. Because you confirm that the links are converted on the frontend.
So I am not exactly sure what you are trying to achieve.
Dave
Hi Dave
All I'm trying to achieve is to convert this
to
or whatever value i have for the umb:// i would like to convert that into a hyperlink in C# code so i can take some action on this.
Thanks
Hi J,
Can I ask which version you are on. The code for doing this depends on that. And also where you want to do this... a view or C# class.
Dave
Hi Dave
Its version 8.17.
Thanks
Hi J,
If you are in a view you can do the following :
In C# classes you can do the following.
You can also inject the IUmbracoContextAccessor instead of using Current to get it.
Dave
is working on a reply...