Copied to clipboard

Flag this post as spam?

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


  • J 445 posts 862 karma points
    Feb 27, 2023 @ 13:59
    J
    0

    Hi

    I select a node in Umbraco. This saves it as

    umb://document/123456
    

    I would like to convert this to the equivalent URL. How could i do that?

    I tried

    var url = Udi.Parse("umb://document/123456");
    

    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

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Feb 27, 2023 @ 14:05
    Dave Woestenborghs
    1

    Hi J,

    What type of property editor are you using for the selecting a node ?

    Dave

  • J 445 posts 862 karma points
    Feb 27, 2023 @ 14:09
    J
    0

    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

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Feb 27, 2023 @ 14:43
    Dave Woestenborghs
    1

    Hi J,

    How are you rendering your RTE ? Umbraco should take of setting the correct url for links in a RTE.

    Dave

  • J 445 posts 862 karma points
    Feb 27, 2023 @ 16:00
    J
    0

    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

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Feb 28, 2023 @ 07:35
    Dave Woestenborghs
    1

    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

  • J 445 posts 862 karma points
    Feb 28, 2023 @ 08:13
    J
    0

    Hi Dave

    All I'm trying to achieve is to convert this

    umb://document/123456
    

    to

    /document/paperclip.docx
    

    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

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Feb 28, 2023 @ 10:36
    Dave Woestenborghs
    1

    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

  • J 445 posts 862 karma points
    Feb 28, 2023 @ 11:26
    J
    0

    Hi Dave

    Its version 8.17.

    Thanks

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Mar 01, 2023 @ 10:17
    Dave Woestenborghs
    100

    Hi J,

    If you are in a view you can do the following :

     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.

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft